DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::appmodel::ConfigurationHelper Class Reference

#include <ConfigurationHelper.hpp>

Collaboration diagram for dunedaq::appmodel::ConfigurationHelper:
[legend]

Public Member Functions

 ConfigurationHelper (const confmodel::Session *ses)
std::vector< const confmodel::Service * > get_services (std::string app_class, std::string data_type)
 Get the exposed Services of all network connections with given data_type from all smart daq applications of given class.
std::vector< std::pair< std::string, const appmodel::NetworkConnectionDescriptor * > > get_netdescriptors (const std::string &data_type, const std::string &app_class="")
 Get all NetworkConnectionDescriptors with given data_type from all applications of given type.
std::map< std::string, std::vector< uint32_t > > get_stream_source_ids ()
 Get the source ids of all DetectorStreams in the Session.
std::map< std::string, std::vector< const SourceIDConf * > > get_tp_source_ids ()
 Get the source ids of all the TP streams in all ReadoutApplications and TriggerApplications.
std::vector< std::string > get_app_uids (std::string app_class="")
 Get list of uids of applications that match given type.
std::map< std::string, const SourceIDConf * > get_app_source_ids (std::string app_class="")
 Get list of source ids for applications that match given type.
std::map< std::string, std::map< std::string, const SourceIDConf * > > get_all_app_source_ids (std::string app_class="")
 Get list of all source ids for applications that match given type. Follows any single value SourceIDConf relationship.
bool is_included (const conffwk::DalObject *item)
 Check the include/exclude state of the given item.
bool is_excluded (const conffwk::DalObject *item)
 Check the include/exclude state of the given item.

Private Attributes

const confmodel::Session * m_session

Detailed Description

Helper class to extract information from Session object without exposing the Session to user code

Provides methods that loop over all applications in the session to get source IDs etc. avoiding the need for individual application's code to access configuration objects of other applications.

Definition at line 38 of file ConfigurationHelper.hpp.

Constructor & Destructor Documentation

◆ ConfigurationHelper()

dunedaq::appmodel::ConfigurationHelper::ConfigurationHelper ( const confmodel::Session * ses)
inlineexplicit

Definition at line 41 of file ConfigurationHelper.hpp.

42 : m_session(ses)
43 {
44 }

Member Function Documentation

◆ get_all_app_source_ids()

std::map< std::string, std::map< std::string, const SourceIDConf * > > ConfigurationHelper::get_all_app_source_ids ( std::string app_class = "")

Get list of all source ids for applications that match given type. Follows any single value SourceIDConf relationship.

Examine all relationships of applications checking for type SourceIDConf generating a map of relationship name to SourceIDConf object pointers

NB: Does not look at multi-value SourceIDConf relationships

Parameters
app_classClass name to select applications by. Empty string implies no selection by class
Returns
A map of application uids to maps relationship to contained source ids

Definition at line 166 of file ConfigurationHelper.cpp.

167{
168 std::map<std::string, std::map<std::string, const SourceIDConf*>> result;
169 for (auto app : m_session->included_applications()) {
170 if (app_class.empty() || app->castable(app_class)) {
171 auto class_info = app->configuration().get_class_info(app->class_name());
172 auto obj = app->config_object();
173 for (auto rel : class_info.p_relationships) {
174 if (rel.p_type == "SourceIDConf") {
175 if (rel.p_cardinality == dunedaq::conffwk::cardinality_t::zero_or_one ||
176 rel.p_cardinality == dunedaq::conffwk::cardinality_t::only_one) {
177 dunedaq::conffwk::ConfigObject rel_obj;
178 obj.get(rel.p_name, rel_obj);
179 if (!rel_obj.is_null()) {
180 if (!result.contains(app->UID())) {
181 result.insert({ app->UID(), {} });
182 }
183 const auto srcid = app->configuration().get<SourceIDConf>(rel_obj);
184 result.at(app->UID()).insert({ rel.p_name, srcid });
185 }
186 } // cardinality
187 } // SourceIDConf
188 } // relationships
189 } // class
190 } // apps
191
192 return result;
193}
bool is_null() const noexcept
Check if object's implementation points to null.
std::vector< const dunedaq::confmodel::Application * > included_applications() const
msgpack::object obj

◆ get_app_source_ids()

std::map< std::string, const SourceIDConf * > ConfigurationHelper::get_app_source_ids ( std::string app_class = "")

Get list of source ids for applications that match given type.

Gather the content of the SmartDaqApplication::source_id relationship for all enabled SmartDaqApplications (or those that match the given class)

Parameters
app_classClass name to select applications by. Empty string implies no selection by class
Returns
A map of application uids to application source ids

Definition at line 151 of file ConfigurationHelper.cpp.

152{
153 std::map<std::string, const SourceIDConf*> result;
154 for (auto app : m_session->included_applications()) {
155 if (app_class.empty() || app->castable(app_class)) {
156 auto smart_app = app->cast<SmartDaqApplication>();
157 if (smart_app != nullptr && smart_app->get_source_id() != nullptr) {
158 result.insert({ app->UID(), smart_app->get_source_id() });
159 }
160 }
161 }
162 return result;
163}

◆ get_app_uids()

std::vector< std::string > ConfigurationHelper::get_app_uids ( std::string app_class = "")

Get list of uids of applications that match given type.

Parameters
app_classClass name to select applications by. Empty string implies no selection by class
Returns
A vector of uids of matching applications

Definition at line 139 of file ConfigurationHelper.cpp.

140{
141 std::vector<std::string> result;
142 for (auto app : m_session->included_applications()) {
143 if (app_class.empty() || app->castable(app_class)) {
144 result.push_back(app->UID());
145 }
146 }
147 return result;
148}

◆ get_netdescriptors()

std::vector< std::pair< std::string, const appmodel::NetworkConnectionDescriptor * > > ConfigurationHelper::get_netdescriptors ( const std::string & data_type,
const std::string & app_class = "" )

Get all NetworkConnectionDescriptors with given data_type from all applications of given type.

Parameters
data_typeData type to match in network descriptor
app_classOptional dal class name to match
Returns
a vector of application uid / network descriptor pairs

Definition at line 35 of file ConfigurationHelper.cpp.

36{
37 std::vector<std::pair<std::string, const appmodel::NetworkConnectionDescriptor*>> result;
38 for (auto app : m_session->included_applications()) {
39 if (app_class.empty() || app->castable(app_class)) {
40 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
41 if (smart_app == nullptr) {
42 // Only SmartDaqApplications have network rules
43 continue;
44 }
45 for (auto rule : smart_app->get_network_rules()) {
46 auto desc = rule->get_descriptor();
47 if (desc->get_data_type() == data_type) {
48 result.emplace_back(std::pair{ app->UID(), desc });
49 }
50 }
51 }
52 }
53 return result;
54}

◆ get_services()

std::vector< const confmodel::Service * > ConfigurationHelper::get_services ( std::string app_class,
std::string data_type )

Get the exposed Services of all network connections with given data_type from all smart daq applications of given class.

Parameters
app_classDal class of applications to match
data_typeData type of network descriptor to match
Returns
A vector of pointers to matching Services

Definition at line 57 of file ConfigurationHelper.cpp.

58{
59 std::vector<const confmodel::Service*> result;
60 for (auto app : m_session->included_applications()) {
61 if (app->castable(app_class)) {
62 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
63 if (smart_app == nullptr) {
64 throw(NotSmart(ERS_HERE, app->full_name()));
65 }
66 for (auto rule : smart_app->get_network_rules()) {
67 if (rule->get_descriptor()->get_data_type() == data_type) {
68 result.push_back(rule->get_descriptor()->get_associated_service());
69 }
70 }
71 }
72 }
73 return result;
74}
#define ERS_HERE

◆ get_stream_source_ids()

std::map< std::string, std::vector< uint32_t > > ConfigurationHelper::get_stream_source_ids ( )

Get the source ids of all DetectorStreams in the Session.

Returns
A map of application uids to vectors of streams that they contain

Definition at line 77 of file ConfigurationHelper.cpp.

78{
79 std::map<std::string, std::vector<uint32_t>> result;
80 for (auto app : m_session->included_applications()) {
81 auto ro_app = app->cast<appmodel::ReadoutApplication>();
82 if (ro_app != nullptr) {
83 std::vector<uint32_t> streams;
84 for (auto res : ro_app->contained_excludable_entities()) {
85 if (!res->is_excluded(*m_session)) {
86 auto d2d = res->cast<confmodel::DetectorToDaqConnection>();
87 if (d2d == nullptr) {
88 throw(BadD2d(ERS_HERE, app->full_name(), res->full_name()));
89 }
90 for (auto stream : d2d->streams()) {
91 if (!stream->is_excluded(*m_session)) {
92 streams.push_back(stream->get_source_id());
93 }
94 }
95 }
96 }
97 result.insert(std::pair{ app->UID(), streams });
98 } else {
99 auto fake_app = app->cast<appmodel::FakeDataApplication>();
100 if (fake_app != nullptr) {
101 std::vector<uint32_t> streams;
102 for (auto res : fake_app->contained_excludable_entities()) {
103 if (!res->is_excluded(*m_session)) {
104 auto fdpc = res->cast<appmodel::FakeDataProdConf>();
105 if (fdpc != nullptr && !fdpc->is_excluded(*m_session)) {
106 streams.push_back(fdpc->get_source_id());
107 }
108 }
109 }
110 result.insert(std::pair(app->UID(), streams));
111 }
112 }
113 }
114 return result;
115}

◆ get_tp_source_ids()

std::map< std::string, std::vector< const SourceIDConf * > > ConfigurationHelper::get_tp_source_ids ( )

Get the source ids of all the TP streams in all ReadoutApplications and TriggerApplications.

Returns
A map of application uids to vectors of contained TP source ids

Definition at line 118 of file ConfigurationHelper.cpp.

119{
120 std::map<std::string, std::vector<const SourceIDConf*>> result;
121 for (auto app : m_session->included_applications()) {
122 auto ro_app = app->cast<appmodel::ReadoutApplication>();
123 if (ro_app != nullptr) {
124 if (ro_app->get_tp_generation_enabled()) {
125 result.insert(std::pair(app->UID(), ro_app->get_tp_source_ids()));
126 } else {
127 result.insert({ app->UID(), std::vector<const SourceIDConf*>() });
128 }
129 }
130 auto replay_app = app->cast<appmodel::TPReplayApplication>();
131 if (replay_app != nullptr) {
132 result.insert(std::pair(app->UID(), replay_app->get_tp_source_ids()));
133 }
134 }
135 return result;
136}

◆ is_excluded()

bool ConfigurationHelper::is_excluded ( const conffwk::DalObject * item)

Check the include/exclude state of the given item.

Parameters
itemThe item to be checked.
Returns
True if the object is excluded

Definition at line 196 of file ConfigurationHelper.cpp.

197{
198 auto res = item->cast<confmodel::ExcludableEntity>();
199 if (res == nullptr) {
200 return false;
201 }
202 return res->is_excluded(*m_session);
203}

◆ is_included()

bool dunedaq::appmodel::ConfigurationHelper::is_included ( const conffwk::DalObject * item)
inline

Check the include/exclude state of the given item.

Parameters
itemThe item to be checked.
Returns
True if the object is included

Definition at line 122 of file ConfigurationHelper.hpp.

122{ return !is_excluded(item); }
bool is_excluded(const conffwk::DalObject *item)
Check the include/exclude state of the given item.

Member Data Documentation

◆ m_session

const confmodel::Session* dunedaq::appmodel::ConfigurationHelper::m_session
private

Definition at line 132 of file ConfigurationHelper.hpp.


The documentation for this class was generated from the following files: