DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
internal
config_api_commands.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
/*
7
* config_api_commands.cpp
8
*
9
* Created on: Apr 19, 2016
10
* Author: Leonidas Georgopoulos
11
*/
12
13
#include "
dbe/Command.hpp
"
14
#include "
dbe/Exceptions.hpp
"
15
#include "
dbe/change_attribute.hpp
"
16
#include "
dbe/change_class.hpp
"
17
#include "
dbe/change_date.hpp
"
18
#include "
dbe/change_enum.hpp
"
19
#include "
dbe/change_time.hpp
"
20
#include "
dbe/confaccessor.hpp
"
21
#include "
dbe/config_api.hpp
"
22
#include "
dbe/config_reference.hpp
"
23
#include "
dbe/confobject_desc.hpp
"
24
#include "
dbe/dbcontroller.hpp
"
25
#include "
dbe/messenger.hpp
"
26
27
#include "
conffwk/Schema.hpp
"
28
#include "
ers/Issue.hpp
"
29
30
#include <QString>
31
#include <QUuid>
32
33
#include <stack>
34
#include <string>
35
#include <vector>
36
37
//------------------------------------------------------------------------------------------
38
// NAMESPACE DBE::CONFIG::API::COMMANDS
39
//------------------------------------------------------------------------------------------
40
/*
41
* Purpose of this namespace is to group all commands that generate undo/redo objects
42
* that acts on config related structures and objects .
43
*
44
* DBE user interface should access the database by appropriately calling methods in this
45
* namespace. Direct access by accessing that database and retrieving ConfigObject directly
46
* is strongly discouraged.
47
*/
48
namespace
dbe
{
49
namespace
config
{
50
namespace
api
{
51
namespace
commands
{
52
53
//------------------------------------------------------------------------------------------
54
void
55
newobj
(std::string
const
& fn,
56
std::string
const
& cn,
57
std::string
const
& name,
58
dbe::t_config_object_preimage::type_attrmap
const
& attributes,
59
dbe::t_config_object_preimage::type_relmap
const
& relations,
60
QUuid
const
& src)
61
{
62
std::string description{
"Object created : "
+ name +
"@"
+ cn };
63
64
config_internal_change
request{
config_internal_change::CREATED
, description, name, cn,
""
};
65
66
confaccessor::get_commands
()->push(
67
new
dbe::actions::object::create
({ attributes, relations, { name, cn }, fn }, src));
68
69
confaccessor::get_internal_change_stack
()->push(request);
70
}
71
//------------------------------------------------------------------------------------------
72
73
//------------------------------------------------------------------------------------------
74
bool
75
delobj
(
tref
obj, QUuid
const
& src)
76
{
77
try
{
78
std::string
const
description{
"Object deleted : "
+ obj.UID() +
"@"
+ obj.class_name() };
79
config_internal_change
request{
config_internal_change::DELETED
, description, obj.UID(), obj.class_name(),
""
};
80
confaccessor::get_commands
()->push(
new
dbe::actions::object::remove
(obj, src));
81
confaccessor::get_internal_change_stack
()->push(request);
82
}
catch
(daq::dbe::ObjectChangeWasNotSuccessful
const
& dbe_err) {
83
INFO
(
"Delete Object: The object could not be deleted!\n\n"
,
dbe::config::errors::parse
(dbe_err).c_str());
84
return
false
;
85
}
86
87
return
true
;
88
}
89
//------------------------------------------------------------------------------------------
90
91
//------------------------------------------------------------------------------------------
92
bool
93
renobj
(
tref
obj, std::string
const
& newuuid, QUuid
const
& src)
94
{
95
try
{
96
std::string
const
description = {
"Object renamed : "
+ obj.UID() +
"@"
+ obj.class_name() +
" to "
+ newuuid +
97
"@"
+ obj.class_name() };
98
99
config_internal_change
request{
config_internal_change::RENAMED
, description, obj.UID(), obj.class_name(),
""
};
100
101
confaccessor::get_commands
()->push(
new
dbe::actions::object::rename
(obj, newuuid, src));
102
103
confaccessor::get_internal_change_stack
()->push(request);
104
105
return
true
;
106
}
catch
(daq::dbe::ObjectChangeWasNotSuccessful
const
& dbe_err) {
107
INFO
(
"It was not possible to rename object "
,
108
dbe::config::errors::parse
(dbe_err).c_str(),
109
"\n\nObject UID:"
,
110
obj.UID().c_str());
111
return
false
;
112
}
113
}
114
//------------------------------------------------------------------------------------------
115
116
//------------------------------------------------------------------------------------------
117
bool
118
movobj
(
tref
obj, std::string
const
& destination, QUuid
const
& src)
119
{
120
try
{
121
std::string
const
description{
"Object "
+ obj.UID() +
"@"
+ obj.class_name() +
" contained in "
+
122
obj.contained_in() +
" moved to "
+ destination };
123
124
config_internal_change
request{
config_internal_change::MOVED
, description, obj.UID(), obj.class_name(),
""
};
125
126
confaccessor::get_commands
()->push(
new
dbe::actions::object::move
(obj, destination, src));
127
confaccessor::get_internal_change_stack
()->push(request);
128
129
return
true
;
130
}
catch
(daq::dbe::ObjectChangeWasNotSuccessful
const
& dbe_err) {
131
INFO
(
"It was not possible to move object "
,
132
dbe::config::errors::parse
(dbe_err).c_str(),
133
"\n\nObject UID:"
,
134
obj.UID().c_str());
135
return
false
;
136
}
137
}
138
//------------------------------------------------------------------------------------------
139
140
//------------------------------------------------------------------------------------------
141
void
142
modobj
(
tref
object
,
const
dunedaq::conffwk::relationship_t
& linkinfo, std::vector<std::string>
const
& others_names)
143
{
144
try
{
145
confaccessor::get_commands
()->push(
new
dbe::actions::object::changerefs
(
object
, linkinfo, others_names));
146
std::string
const
description(others_names.size() != 1 ?
"Multi Relationship : "
+ linkinfo.
p_name
147
:
"Single Relationship : "
+ linkinfo.
p_name
);
148
149
config_internal_change
const
change{
150
config_internal_change::MODIFIED
, description,
object
.UID(),
object
.class_name(),
""
151
};
152
153
confaccessor::get_internal_change_stack
()->push(change);
154
}
catch
(daq::dbe::ObjectChangeWasNotSuccessful
const
& dbe_err) {
155
WARN
(
"The object reference could not be changed"
,
dbe::config::errors::parse
(dbe_err).c_str());
156
}
157
}
158
//------------------------------------------------------------------------------------------
159
160
//------------------------------------------------------------------------------------------
161
template
<>
162
void
163
modobj<std::string>
(
tref
Object,
const
dunedaq::conffwk::attribute_t
& AttributeData, std::string Value)
164
{
165
try
{
166
config_internal_change
Change;
167
Change.
uid
= Object.
UID
();
168
Change.
classname
= Object.
class_name
();
169
Change.
request
=
config_internal_change::MODIFIED
;
170
Change.
description
= QString(
"Attribute "
).append(AttributeData.
p_name
.c_str()).toStdString();
171
172
if
(AttributeData.
p_type
==
dunedaq::conffwk::string_type
) {
173
confaccessor::get_commands
()->push(
new
dbe::actions::ChangeAttribute<std::string>
(Object, AttributeData, Value));
174
}
else
if
(AttributeData.
p_type
==
dunedaq::conffwk::enum_type
) {
175
confaccessor::get_commands
()->push(
new
dbe::actions::ChangeEnum<std::string>
(Object, AttributeData, Value));
176
}
else
if
(AttributeData.
p_type
==
dunedaq::conffwk::class_type
) {
177
confaccessor::get_commands
()->push(
new
dbe::actions::ChangeClass<std::string>
(Object, AttributeData, Value));
178
}
else
if
(AttributeData.
p_type
==
dunedaq::conffwk::date_type
) {
179
180
confaccessor::get_commands
()->push(
new
dbe::actions::ChangeDate<std::string>
(Object, AttributeData, Value));
181
}
else
if
(AttributeData.
p_type
==
dunedaq::conffwk::time_type
) {
182
confaccessor::get_commands
()->push(
new
dbe::actions::ChangeTime<std::string>
(Object, AttributeData, Value));
183
}
184
185
confaccessor::get_internal_change_stack
()->push(Change);
186
}
catch
(daq::dbe::ObjectChangeWasNotSuccessful
const
& dbe_err) {
187
WARN
(
"The object attribute could not be changed"
,
dbe::config::errors::parse
(dbe_err).c_str());
188
}
189
}
190
//------------------------------------------------------------------------------------------
191
192
//------------------------------------------------------------------------------------------
193
template
<>
194
void
195
modobj<std::vector<std::string>
>(
tref
Object,
196
const
dunedaq::conffwk::attribute_t
& AttributeData,
197
std::vector<std::string> Value)
198
{
199
try
{
200
config_internal_change
Change;
201
Change.
uid
= Object.UID();
202
Change.
classname
= Object.class_name();
203
Change.
request
=
config_internal_change::MODIFIED
;
204
Change.
description
= QString(
"Attribute "
).append(AttributeData.p_name.c_str()).toStdString();
205
206
if
(AttributeData.p_type ==
dunedaq::conffwk::string_type
) {
207
confaccessor::get_commands
()->push(
208
new
dbe::actions::ChangeAttribute
<std::vector<std::string>>(Object, AttributeData, Value));
209
}
else
if
(AttributeData.p_type ==
dunedaq::conffwk::enum_type
) {
210
confaccessor::get_commands
()->push(
211
new
dbe::actions::ChangeEnum
<std::vector<std::string>>(Object, AttributeData, Value));
212
}
else
if
(AttributeData.p_type ==
dunedaq::conffwk::class_type
) {
213
confaccessor::get_commands
()->push(
214
new
dbe::actions::ChangeClass
<std::vector<std::string>>(Object, AttributeData, Value));
215
}
else
if
(AttributeData.p_type ==
dunedaq::conffwk::date_type
) {
216
confaccessor::get_commands
()->push(
217
new
dbe::actions::ChangeDate
<std::vector<std::string>>(Object, AttributeData, Value));
218
}
else
if
(AttributeData.p_type ==
dunedaq::conffwk::time_type
) {
219
confaccessor::get_commands
()->push(
220
new
dbe::actions::ChangeTime
<std::vector<std::string>>(Object, AttributeData, Value));
221
}
222
223
confaccessor::get_internal_change_stack
()->push(Change);
224
}
catch
(daq::dbe::ObjectChangeWasNotSuccessful
const
& dbe_err) {
225
WARN
(
"The object attribute could not be changed"
,
dbe::config::errors::parse
(dbe_err).c_str());
226
}
227
}
228
//------------------------------------------------------------------------------------------
229
230
//------------------------------------------------------------------------------------------
231
232
//------------------------------------------------------------------------------------------
233
namespace
file {
234
void
235
remove
(QString
const
& db, QString
const
& fn)
236
{
237
std::string dbname = db.toStdString();
238
std::string sinclude = fn.toStdString();
239
240
try
{
241
config_internal_change
Change;
242
Change.
filename
= fn.toStdString();
243
Change.
request
=
config_internal_change::FILE_DELETED
;
244
Change.
description
= QString(
"File(deleted) : "
).append(fn).toStdString();
245
246
confaccessor::get_commands
()->push(
new
dbe::actions::file::remove
(dbname, sinclude));
247
confaccessor::get_internal_change_stack
()->push(Change);
248
}
catch
(daq::dbe::DatabaseChangeNotSuccessful
const
& dbe_err) {
249
WARN
(
"File removal failure"
,
dbe::config::errors::parse
(dbe_err).c_str());
250
}
251
}
252
253
void
254
add
(
const
QString& Database,
const
QString& IncludedFile)
255
{
256
std::string dbname = Database.toStdString();
257
std::string sinclude = IncludedFile.toStdString();
258
259
try
{
260
config_internal_change
Change;
261
Change.
filename
= IncludedFile.toStdString();
262
Change.
request
=
config_internal_change::FILE_INCLUDED
;
263
Change.
description
= QString(
"File(included) : "
).append(IncludedFile).toStdString();
264
265
confaccessor::get_commands
()->push(
new
dbe::actions::file::add
(dbname, sinclude));
266
confaccessor::get_internal_change_stack
()->push(Change);
267
}
catch
(daq::dbe::DatabaseChangeNotSuccessful
const
& dbe_err) {
268
WARN
(
"File inclusion did not succeed"
,
dbe::config::errors::parse
(dbe_err).c_str());
269
}
270
}
271
272
}
273
274
}
275
}
276
}
277
}
278
//------------------------------------------------------------------------------------------
Command.hpp
Exceptions.hpp
Issue.hpp
change_attribute.hpp
change_class.hpp
change_date.hpp
change_enum.hpp
change_time.hpp
dbe::actions::ChangeAttribute
Definition
change_attribute.hpp:39
dbe::actions::ChangeClass
Definition
change_class.hpp:37
dbe::actions::ChangeDate
Definition
change_date.hpp:36
dbe::actions::ChangeEnum
Definition
change_enum.hpp:38
dbe::actions::ChangeTime
Definition
change_time.hpp:36
dbe::actions::file::add
Definition
Command.hpp:167
dbe::actions::file::remove
Definition
Command.hpp:181
dbe::actions::object::changerefs
Definition
Command.hpp:128
dbe::actions::object::create
Definition
Command.hpp:86
dbe::actions::object::move
Definition
Command.hpp:147
dbe::actions::object::remove
Definition
Command.hpp:100
dbe::actions::object::rename
Definition
Command.hpp:114
dbe::confaccessor::get_commands
static t_undo_stack_cptr get_commands()
Definition
confaccessor.cpp:164
dbe::confaccessor::get_internal_change_stack
static t_internal_changes_stack_cptr get_internal_change_stack()
Definition
confaccessor.cpp:463
dbe::inner::configobject::ref_interface::class_name
std::string class_name() const
Definition
config_reference.hpp:180
dbe::inner::configobject::ref_interface::UID
std::string UID() const
Definition
config_reference.hpp:178
confaccessor.hpp
Schema.hpp
config_api.hpp
config_reference.hpp
confobject_desc.hpp
dbcontroller.hpp
messenger.hpp
WARN
#define WARN(...)
Definition
messenger.hpp:82
INFO
#define INFO(...)
Definition
messenger.hpp:98
dbe::config::api::commands::file::remove
void remove(QString const &db, QString const &fn)
Definition
config_api_commands.cpp:235
dbe::config::api::commands::file::add
void add(QString const &db, QString const &fn)
Definition
config_api_commands.cpp:254
dbe::config::api::commands
Definition
config_api.hpp:94
dbe::config::api::commands::modobj< std::string >
void modobj< std::string >(tref Object, const dunedaq::conffwk::attribute_t &AttributeData, std::string Value)
Definition
config_api_commands.cpp:163
dbe::config::api::commands::newobj
void newobj(std::string const &fn, std::string const &class_name, std::string const &UID, dbe::t_config_object_preimage::type_attrmap const &attributes, dbe::t_config_object_preimage::type_relmap const &relations, QUuid const &src)
Definition
config_api_commands.cpp:55
dbe::config::api::commands::renobj
bool renobj(inner::configobject::tref obj, std::string const &newuuid, QUuid const &src)
Definition
config_api_commands.cpp:93
dbe::config::api::commands::modobj
void modobj(tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T Value)
Definition
config_api.hpp:97
dbe::config::api::commands::movobj
bool movobj(inner::configobject::tref obj, std::string const &destination, QUuid const &src)
Definition
config_api_commands.cpp:118
dbe::config::api::commands::delobj
bool delobj(inner::configobject::tref obj, QUuid const &src)
Definition
config_api_commands.cpp:75
dbe::config::api
Definition
config_api.hpp:30
dbe::config::errors::parse
std::string const parse(ers::Issue const &)
Definition
config_api.cpp:98
dbe::config
Definition
config_api.hpp:29
dbe
Include QT Headers.
Definition
BatchChangeWidget.hpp:16
dbe::tref
inner::configobject::tref tref
Definition
tref.hpp:36
dunedaq::conffwk::date_type
@ date_type
Definition
Schema.hpp:40
dunedaq::conffwk::string_type
@ string_type
Definition
Schema.hpp:42
dunedaq::conffwk::enum_type
@ enum_type
Definition
Schema.hpp:43
dunedaq::conffwk::class_type
@ class_type
Definition
Schema.hpp:44
dunedaq::conffwk::time_type
@ time_type
Definition
Schema.hpp:41
dbe::config_internal_change
Definition
confaccessor.hpp:28
dbe::config_internal_change::description
std::string description
Definition
confaccessor.hpp:42
dbe::config_internal_change::request
modification request
Type of modification.
Definition
confaccessor.hpp:41
dbe::config_internal_change::filename
std::string filename
Definition
confaccessor.hpp:47
dbe::config_internal_change::classname
std::string classname
Definition
confaccessor.hpp:46
dbe::config_internal_change::FILE_INCLUDED
@ FILE_INCLUDED
Definition
confaccessor.hpp:36
dbe::config_internal_change::RENAMED
@ RENAMED
Definition
confaccessor.hpp:34
dbe::config_internal_change::MOVED
@ MOVED
Definition
confaccessor.hpp:35
dbe::config_internal_change::DELETED
@ DELETED
Definition
confaccessor.hpp:32
dbe::config_internal_change::FILE_DELETED
@ FILE_DELETED
Definition
confaccessor.hpp:37
dbe::config_internal_change::CREATED
@ CREATED
Definition
confaccessor.hpp:31
dbe::config_internal_change::MODIFIED
@ MODIFIED
Definition
confaccessor.hpp:33
dbe::config_internal_change::uid
std::string uid
Object Identification.
Definition
confaccessor.hpp:45
dbe::config_object_image< S, config_object_key< S >, S >::type_relmap
std::map< type_str, type_images > type_relmap
Definition
confobject_desc.hpp:109
dbe::config_object_image< S, config_object_key< S >, S >::type_attrmap
std::map< type_str, type_attributes > type_attrmap
Definition
confobject_desc.hpp:108
dunedaq::conffwk::attribute_t
Definition
Schema.hpp:60
dunedaq::conffwk::attribute_t::p_name
std::string p_name
Definition
Schema.hpp:62
dunedaq::conffwk::attribute_t::p_type
type_t p_type
Definition
Schema.hpp:63
dunedaq::conffwk::relationship_t
Definition
Schema.hpp:117
dunedaq::conffwk::relationship_t::p_name
std::string p_name
Definition
Schema.hpp:119
Generated on
for DUNE-DAQ by
1.18.0