Skip to content

Commit

Permalink
Merge pull request #19 from DUNE-DAQ/plasorak/commandlineparam-method-2
Browse files Browse the repository at this point in the history
Carbon copy of PR18
  • Loading branch information
plasorak committed Apr 26, 2024
2 parents f2ef24a + 0d69fb5 commit 8021af4
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 91 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

cmake_minimum_required(VERSION 3.12)
project(coredal VERSION 1.2.0)

Expand Down
94 changes: 92 additions & 2 deletions include/coredal/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@
#include "oksdbinterfaces/DalObject.hpp"
#include "nlohmann/json.hpp"

#include "coredal/Application.hpp"
#include "coredal/PhysicalHost.hpp"
#include "coredal/Segment.hpp"
#include "coredal/Service.hpp"
#include "coredal/Session.hpp"
#include "coredal/VirtualHost.hpp"

namespace dunedaq {
ERS_DECLARE_ISSUE(
coredal,
ConfigurationError,
,
)


ERS_DECLARE_ISSUE_BASE(
coredal,
NoOpmonInfrastructure,
ConfigurationError,
"The opmon infrastructure has not been set up in the configuration",
,
)

ERS_DECLARE_ISSUE_BASE(
coredal,
NoControlServiceDefined,
ConfigurationError,
"The control service has not been set up for the application " + app_name + " you need to define a service called " + app_name + "_control",
,
((std::string)app_name)

)


namespace coredal {
class Session;

/**
* \brief Get session object.
Expand All @@ -22,7 +52,7 @@ namespace coredal {
*
* The last parameter of the algorithm can be used to optimise performance
* of the DAL in case if a database server config implementation %is used.
* The parameter defines how many layers of objects referenced by given
* The parameter defines how many layers of objects referenced by given
* session object should be read into client's config cache together with
* session object during single network operation. For example:
* - if the parameter %is 0, then only session object %is read;
Expand Down Expand Up @@ -56,6 +86,65 @@ namespace coredal {
attributes[name] = nlohmann::json(value_vector);
}
}

template<typename T>
const std::vector<std::string> construct_commandline_parameters_appfwk(const T* app,
const oksdbinterfaces::Configuration& confdb,
const dunedaq::coredal::Session* session) {

const dunedaq::coredal::Service* control_service = nullptr;

for (auto const* as: app->get_exposes_service())
if (as->UID() == app->UID()+"_control") // unclear this is the best way to do this.
control_service = as;

if (control_service == nullptr)
throw NoControlServiceDefined(ERS_HERE, app->UID());

const std::string control_uri =
control_service->get_protocol()
+ "://"
+ app->get_runs_on()->get_runs_on()->UID()
+ ":"
+ std::to_string(control_service->get_port());

const dunedaq::coredal::Application* opmon_app = nullptr;
for (auto const* ia: session->get_infrastructure_applications())
if (ia->castable("OpMonService"))
opmon_app = ia;

if (opmon_app == nullptr)
throw NoOpmonInfrastructure(ERS_HERE, session->UID());

const dunedaq::coredal::Service* opmon_service = opmon_app->get_exposes_service()[0];
std::string opmon_uri =
opmon_service->get_protocol()
+ "://"
+ opmon_app->get_runs_on()->get_runs_on()->UID()
+ ":"
+ std::to_string(opmon_service->get_port())
+ opmon_service->get_path();

if (opmon_service->get_protocol() == "file")
opmon_uri =
opmon_service->get_protocol()
+ "://"
+ opmon_service->get_path();

const std::string configuration_uri = confdb.get_impl_spec();

return {
"--name",
app->UID(),
"-c",
control_uri,
"-i",
opmon_uri,
"--configurationService",
configuration_uri,
};
}

} // namespace coredal


Expand Down Expand Up @@ -287,6 +376,7 @@ namespace coredal {
((std::string)second)
)


} // namespace dunedaq

#endif
34 changes: 30 additions & 4 deletions pybindsrc/dal_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "coredal/Application.hpp"
#include "coredal/DaqApplication.hpp"
#include "coredal/HostComponent.hpp"
#include "coredal/RCApplication.hpp"
#include "coredal/Session.hpp"


Expand All @@ -25,7 +26,7 @@ namespace dunedaq::coredal::python {

struct ObjectLocator {
ObjectLocator(const std::string& id_arg, const std::string& class_name_arg) :
id(id_arg), class_name(class_name_arg)
id(id_arg), class_name(class_name_arg)
{}
const std::string id;
const std::string class_name;
Expand Down Expand Up @@ -57,6 +58,13 @@ namespace dunedaq::coredal::python {
}

bool component_disabled(const Configuration& db, const std::string& session_id, const std::string& component_id) {
try {
ConfigObject object;
const_cast<Configuration&>(db).get("Component", component_id, object);
}
catch (oksdbinterfaces::NotFound& except) {
return false;
}
const dunedaq::coredal::Component* component_ptr = const_cast<Configuration&>(db).get<dunedaq::coredal::Component>(component_id);
const dunedaq::coredal::Session* session_ptr = const_cast<Configuration&>(db).get<dunedaq::coredal::Session>(session_id);

Expand All @@ -75,11 +83,11 @@ namespace dunedaq::coredal::python {

component_ptr->get_parents(*session_ptr, parents);

for (const auto& parent : parents) {
for (const auto& parent : parents) {
std::vector<ObjectLocator> parents_components;
for (const auto& ancestor_component_ptr : parent) {
for (const auto& ancestor_component_ptr : parent) {
parents_components.emplace_back(
ObjectLocator(ancestor_component_ptr->UID(),
ObjectLocator(ancestor_component_ptr->UID(),
ancestor_component_ptr->class_name()) );
}
parent_ids.emplace_back(parents_components);
Expand All @@ -95,6 +103,22 @@ namespace dunedaq::coredal::python {
}
return resources;
}

std::vector<std::string> daq_application_construct_commandline_parameters(const Configuration& db,
const std::string& session_id,
const std::string& app_id) {
const auto* app = const_cast<Configuration&>(db).get<dunedaq::coredal::DaqApplication>(app_id);
const auto* session = const_cast<Configuration&>(db).get<dunedaq::coredal::Session>(session_id);
return app->construct_commandline_parameters(db, session);
}

std::vector<std::string> rc_application_construct_commandline_parameters(const Configuration& db,
const std::string& session_id,
const std::string& app_id) {
const auto* app = const_cast<Configuration&>(db).get<dunedaq::coredal::RCApplication>(app_id);
const auto* session = const_cast<Configuration&>(db).get<dunedaq::coredal::Session>(session_id);
return app->construct_commandline_parameters(db, session);
}
void
register_dal_methods(py::module& m)
{
Expand All @@ -110,6 +134,8 @@ register_dal_methods(py::module& m)
m.def("component_disabled", &component_disabled, "Determine if a Component-derived object (e.g. a Segment) has been disabled");
m.def("component_get_parents", &component_get_parents, "Get the Component-derived class instances of the parent(s) of the Component-derived object in question");
m.def("daqapp_get_used_resources", &daq_application_get_used_hostresources, "Get list of HostResources used by DAQApplication");
m.def("daq_application_construct_commandline_parameters", &daq_application_construct_commandline_parameters, "Get a version of the command line agruments parsed");
m.def("rc_application_construct_commandline_parameters", &rc_application_construct_commandline_parameters, "Get a version of the command line agruments parsed");
}

} // namespace dunedaq::coredal::python
16 changes: 15 additions & 1 deletion schema/coredal/dunedaq.schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
<relationship name="applicationEnvironment" description="Define process environment for this application." class-type="VariableBase" low-cc="zero" high-cc="many" is-composite="no" is-exclusive="no" is-dependent="no"/>
<relationship name="runs_on" description="VirtualHost to run this application on" class-type="VirtualHost" low-cc="one" high-cc="one" is-composite="yes" is-exclusive="no" is-dependent="yes"/>
<relationship name="exposes_service" description="Services exposed i.e. provided by this application" class-type="Service" low-cc="zero" high-cc="many" is-composite="yes" is-exclusive="no" is-dependent="yes"/>
<method name="parse_commandline_parameters" description="Get the CLA for the application">
<method-implementation language="c++" prototype=" const std::vector&lt;std::string&gt; parse_commandline_parameters() const" body=""/>
</method>
</class>

<class name="Component" description="Abstract base class for Segment and Resource classes. It is only used to allow objects of derived classes to be put into list of disabled items. For more information read https://twiki.cern.ch/twiki/bin/viewauth/Atlas/DaqHltDal#3_4_Resource_Classes" is-abstract="yes">
Expand All @@ -110,6 +113,10 @@
<attribute name="threads" description="Number of worker threads (not the number of workers which are processes)" type="u16" init-value="1" is-not-null="yes"/>
</class>

<class name="OpMonService">
<superclass name="Application"/>
</class>

<class name="DROStreamConf">
<superclass name="ResourceBase"/>
<attribute name="source_id" type="u32" is-not-null="yes"/>
Expand All @@ -124,6 +131,9 @@
<method name="get_used_hostresources" description="Get the set of all HostComponents used by this application">
<method-implementation language="c++" prototype=" std::set&lt;const dunedaq::coredal::HostComponent*&gt; get_used_hostresources() const" body=""/>
</method>
<method name="construct_commandline_parameters" description="get the command line parameters for this application">
<method-implementation language="c++" prototype=" const std::vector&lt;std::string&gt; construct_commandline_parameters(const oksdbinterfaces::Configuration&amp; confdb, const dunedaq::coredal::Session* session) const" body="BEGIN_HEADER_PROLOGUE&#xA;#include &quot;coredal/util.hpp&quot;&#xA;END_HEADER_PROLOGUE"/>
</method>
</class>

<class name="DaqModule" description="A plugin module for the app framework" is-abstract="yes">
Expand Down Expand Up @@ -235,7 +245,10 @@
<attribute name="application_name" type="string" init-value="controller" is-not-null="yes"/>
<relationship name="fsm" class-type="FSMconfiguration" low-cc="one" high-cc="one" is-composite="yes" is-exclusive="no" is-dependent="yes"/>
<relationship name="broadcaster" class-type="RCBroadcaster" low-cc="zero" high-cc="one" is-composite="yes" is-exclusive="no" is-dependent="no"/>
</class>
<method name="construct_commandline_parameters" description="get the command line parameters for this rc application">
<method-implementation language="c++" prototype=" const std::vector&lt;std::string&gt; construct_commandline_parameters(const oksdbinterfaces::Configuration&amp; confdb, const dunedaq::coredal::Session* session) const" body=""/> <!-- BEGIN_HEADER_PROLOGUE&#xA;#include &quot;coredal/util.hpp&quot;&#xA;END_HEADER_PROLOGUE"/> -->
</method>
</class>

<class name="RCBroadcaster">
<attribute name="type" type="enum" range="kafka,undefined" init-value="kafka" is-not-null="yes"/>
Expand Down Expand Up @@ -287,6 +300,7 @@
<attribute name="protocol" type="string" init-value="tcp" is-not-null="yes"/>
<attribute name="port" type="u16" init-value="5000"/>
<attribute name="eth_device_name" type="string"/>
<attribute name="path" type="string" init-value=""/>
</class>

<class name="Session">
Expand Down
83 changes: 0 additions & 83 deletions scripts/app_environment.py

This file was deleted.

0 comments on commit 8021af4

Please sign in to comment.