DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DalObject.cpp
Go to the documentation of this file.
2
3namespace dunedaq {
4namespace conffwk {
5
6bool
7DalObject::get_rel_objects(const std::string& name, bool upcast_unregistered, std::vector<const DalObject*>& objs) const
8{
9 std::vector<conffwk::ConfigObject> c_objs;
10
11 if (const_cast<conffwk::ConfigObject*>(&p_obj)->rel(name, c_objs)) {
12 // Fixme: what about the lock?
13 // std::lock_guard<std::mutex> scoped_lock(p_registry.m_tmpl_mutex);
14 p_registry.get(c_objs, upcast_unregistered).swap(objs);
15 return true;
16 }
17
18 return false;
19}
20
21bool
22DalObject::get_algo_objects(const std::string& /* name */, std::vector<const DalObject*>& /* objs */) const
23{
24 // FIXME: Remove
25 // const std::string &suitable_dal_class = DalFactory::instance().class4algo(p_registry, class_name(), name);
26
27 // TLOG_DEBUG(2) << "suitable class for algorithm " << name << " on object " << this << " is " <<
28 // suitable_dal_class;
29
30 // if (!suitable_dal_class.empty())
31 // if (const DalObject *obj = p_registry.make_dal_object(const_cast<conffwk::ConfigObject&>(p_obj), UID(),
32 // suitable_dal_class))
33 // {
34 // obj->get(name, false).swap(objs);
35 // return true;
36 // }
37
38 return false;
39}
40
41// DalObject helper
42
43void
44DalObject::p_null(std::ostream& s)
45{
46 s << "(null)";
47}
48
49void
50DalObject::p_rm(std::ostream& s)
51{
52 s << "(deleted object)";
53}
54
55void
56DalObject::p_error(std::ostream& s, dunedaq::conffwk::Exception& ex)
57{
58 s << "ERROR in generated DAL print method:\n\twas caused by: " << ex << std::endl;
59}
60
61void
62DalObject::p_hdr(std::ostream& s, unsigned int indent, const std::string& cl, const char* nm) const
63{
64 const std::string str(indent, ' ');
65 s << str;
66 if (nm)
67 s << nm << ' ';
68 s << cl << " object:\n" << str << " id: \'" << UID() << "\', class name: \'" << DalObject::class_name() << "\'\n";
69}
70
71void
72DalObject::throw_init_ex(dunedaq::conffwk::Exception& ex)
73{
74 std::ostringstream text;
75 text << "failed to init " << this << ":\n\twas caused by: " << ex << std::endl;
76 p_was_read = false;
77 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
78}
79
80void
81DalObject::throw_get_ex(const std::string& what, const std::string& class_name, const DalObject* obj)
82{
83 std::ostringstream text;
84 text << "cannot find relationship or algorithm \"" << what << "\" in c++ class \"" << class_name << "\" for object "
85 << obj;
86 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
87}
88
89std::ostream&
90operator<<(std::ostream& s, const DalObject* obj)
91{
92 if (obj == nullptr)
94 else if (obj->is_deleted())
95 s << "(deleted object " << obj->UID() << '@' << obj->class_name() << ')';
96 else
97 s << '\'' << obj->UID() << '@' << obj->class_name() << '\'';
98
99 return s;
100}
101
102void
103p_sv_rel(std::ostream& s, const std::string& str, const std::string& name, const DalObject* obj)
104{
105 s << str << name << ": " << obj << '\n';
106}
107
108} // namespace conffwk
109
110} // namespace dunedaq
#define ERS_HERE
The base class for any generated DAL object.
Definition DalObject.hpp:51
void p_hdr(std::ostream &s, unsigned int indent, const std::string &cl, const char *nm=nullptr) const
print object headers
Definition DalObject.cpp:62
static void p_null(std::ostream &s)
print "(null)"
Definition DalObject.cpp:44
static void p_rm(std::ostream &s)
print "(deleted object)"
Definition DalObject.cpp:50
void throw_init_ex(dunedaq::conffwk::Exception &ex)
throw object initialisation exception (i.e.
Definition DalObject.cpp:72
const std::string & class_name() const noexcept
static void p_error(std::ostream &s, dunedaq::conffwk::Exception &ex)
print error text
Definition DalObject.cpp:56
bool get_rel_objects(const std::string &name, bool upcast_unregistered, std::vector< const DalObject * > &objs) const
Read relationship values as DAL objects using DAL factory.
Definition DalObject.cpp:7
static void throw_get_ex(const std::string &what, const std::string &class_name, const DalObject *obj)
throw exception in generated get method (i.e.
Definition DalObject.cpp:81
DalObject(DalRegistry &db, const ConfigObject &o) noexcept
Definition DalObject.hpp:64
const std::string & UID() const noexcept
DalRegistry & p_registry
Configuration object.
bool p_was_read
is true, if the object was read
bool get_algo_objects(const std::string &name, std::vector< const DalObject * > &objs) const
Run algorithm and return result as DAL objects using DAL factory.
Definition DalObject.cpp:22
ConfigObject p_obj
Config object used by given template object.
friend std::ostream & operator<<(std::ostream &s, const DalObject *obj)
Definition DalObject.cpp:90
DalObject * get(ConfigObject &obj, bool upcast_unregistered=false)
void p_sv_rel(std::ostream &s, const std::string &str, const std::string &name, const DalObject *obj)
print weak single-value relationship
The DUNE-DAQ namespace.
msgpack::object obj