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_enabled (const conffwk::DalObject *item)
 Check the enabled state of the given item.
 
bool is_disabled (const conffwk::DalObject *item)
 Check the enabled state of the given item.
 

Private Attributes

const confmodel::Sessionm_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 40 of file ConfigurationHelper.hpp.

41 : m_session(ses) {}

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 169 of file ConfigurationHelper.cpp.

169 {
170 std::map<std::string, std::map<std::string, const SourceIDConf*>> result;
171 for (auto app: m_session->enabled_applications()) {
172 if (app_class.empty() || app->castable(app_class)) {
173 auto class_info = app->configuration().get_class_info(app->class_name());
174 auto obj = app->config_object();
175 for (auto rel: class_info.p_relationships) {
176 if (rel.p_type == "SourceIDConf") {
177 if (rel.p_cardinality == dunedaq::conffwk::cardinality_t::zero_or_one ||
178 rel.p_cardinality == dunedaq::conffwk::cardinality_t::only_one) {
180 obj.get(rel.p_name, rel_obj);
181 if (!rel_obj.is_null()) {
182 if (!result.contains(app->UID())) {
183 result.insert({app->UID(), {}});
184 }
185 const auto srcid = app->configuration().get<SourceIDConf>(rel_obj);
186 result.at(app->UID()).insert({rel.p_name, srcid});
187 }
188 } // cardinality
189 } // SourceIDConf
190 } // relationships
191 } // class
192 } // apps
193
194 return result;
195}
Represents database objects.
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
bool is_null() const noexcept
Check if object's implementation points to null.
std::vector< const dunedaq::confmodel::Application * > enabled_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 154 of file ConfigurationHelper.cpp.

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

◆ 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 142 of file ConfigurationHelper.cpp.

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

◆ 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.

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

◆ 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 59 of file ConfigurationHelper.cpp.

62{
63 std::vector<const confmodel::Service*> result;
64 for (auto app: m_session->enabled_applications()) {
65 if (app->castable(app_class)) {
66 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
67 if (smart_app == nullptr) {
68 throw (NotSmart(ERS_HERE, app->full_name()));
69 }
70 for (auto rule: smart_app->get_network_rules()) {
71 if (rule->get_descriptor()->get_data_type() == data_type) {
72 result.push_back(rule->get_descriptor()->get_associated_service());
73 }
74 }
75 }
76 }
77 return result;
78}
#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 81 of file ConfigurationHelper.cpp.

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

◆ 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 122 of file ConfigurationHelper.cpp.

122 {
123 std::map<std::string, std::vector<const SourceIDConf*>> result;
124 for (auto app: m_session->enabled_applications()) {
125 auto ro_app = app->cast<appmodel::ReadoutApplication>();
126 if (ro_app != nullptr) {
127 if (ro_app->get_tp_generation_enabled()) {
128 result.insert(std::pair(app->UID(), ro_app->get_tp_source_ids()));
129 }
130 else {
131 result.insert({app->UID(), std::vector<const SourceIDConf*>()});
132 }
133 }
134 auto replay_app = app->cast<appmodel::TPReplayApplication>();
135 if (replay_app != nullptr) {
136 result.insert(std::pair(app->UID(), replay_app->get_tp_source_ids()));
137 }
138 }
139 return result;
140}
const TARGET * cast() const noexcept
Casts object to different class.

◆ is_disabled()

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

Check the enabled state of the given item.

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

Definition at line 197 of file ConfigurationHelper.cpp.

197 {
198 auto res = item->cast<confmodel::Resource>();
199 if (res == nullptr) {
200 return false;
201 }
202 return res->is_disabled(*m_session);
203}
bool is_disabled(const dunedaq::confmodel::ResourceTree &session) const

◆ is_enabled()

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

Check the enabled state of the given item.

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

Definition at line 132 of file ConfigurationHelper.hpp.

132 {
133 return !is_disabled(item);
134 }
bool is_disabled(const conffwk::DalObject *item)
Check the enabled state of the given item.

Member Data Documentation

◆ m_session

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

Definition at line 144 of file ConfigurationHelper.hpp.


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