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