DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OksConfiguration.cpp File Reference
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include <algorithm>
#include <memory>
#include "ers/ers.hpp"
#include "oks/file.hpp"
#include "oks/kernel.hpp"
#include "oks/object.hpp"
#include "oks/query.hpp"
#include "oks/relationship.hpp"
#include "oksutils/oks/access.hpp"
#include "conffwk/Configuration.hpp"
#include "conffwk/ConfigObject.hpp"
#include "conffwk/Change.hpp"
#include "conffwk/Schema.hpp"
#include "oksconflibs/OksConfiguration.hpp"
#include "oksconflibs/OksConfigObject.hpp"
Include dependency graph for OksConfiguration.cpp:

Go to the source code of this file.

Classes

struct  dunedaq::oksconflibs::OksConfigurationCheckDB
class  dunedaq::oksconflibs::ResubscribeGuard
struct  InheritanceData
class  DestroyGuard1
class  DestroyGuard2

Namespaces

namespace  dunedaq
 The DUNE-DAQ namespace.
namespace  dunedaq::oksconflibs

Functions

conffwk::ConfigurationImpl * _oksconflibs_creator_ (const std::string &spec)
bool is_repo_name (const std::string &name)
static std::string mk_no_file_error_text (const std::string &db)
static std::string mk_add_include_error_text (const std::string &db, const std::string &include, const char *error=nullptr)
static void throw_update_exception (const OksFile *file_h, const char *action, const char *reason)
static std::vector< dunedaq::conffwk::Versiondunedaq::oksconflibs::oks2config (const std::vector< OksRepositoryVersion > &in)
static void check (std::vector< conffwk::ConfigurationChange * > &changes, const InheritanceData &inheritance, const std::set< std::string > &class_names, const OksConfiguration::SMap &objects, const std::string &obj_class, const std::string &obj_id, const char action)
static std::string mk_rm_include_error_text (const std::string &db, const std::string &include, const char *error=0)

Function Documentation

◆ _oksconflibs_creator_()

conffwk::ConfigurationImpl * _oksconflibs_creator_ ( const std::string & spec)

Definition at line 41 of file OksConfiguration.cpp.

41 {
42 try {
43 std::unique_ptr<OksConfiguration> impl(new OksConfiguration());
44 if(!spec.empty()) { impl->open_db(spec); }
45 return impl.release();
46 }
47 catch(dunedaq::conffwk::Exception & ex) {
48 throw dunedaq::conffwk::Generic(ERS_HERE, "oksconflibs initialization error", ex);
49 }
50 catch(...) {
51 throw dunedaq::conffwk::Generic(ERS_HERE, "oksconflibs initialization error:\n***** caught unknown exception *****");
52 }
53}
#define ERS_HERE

◆ check()

void check ( std::vector< conffwk::ConfigurationChange * > & changes,
const InheritanceData & inheritance,
const std::set< std::string > & class_names,
const OksConfiguration::SMap & objects,
const std::string & obj_class,
const std::string & obj_id,
const char action )
static

The function checks if the object satisfies the subscription and adds to changes. The actions could be: '+' - created '~' - changed '-' - deleted

Definition at line 981 of file OksConfiguration.cpp.

988 {
989
990 bool any = (class_names.empty() && objects.empty());
991
992
993 // check subscription on objects
994 //
995 // omi iterator in non-null, if on an object of class 'obj_class'
996 // there is explicit subscription
997
998 OksConfiguration::SMap::const_iterator omi = objects.end();
999
1000 if(action != '+') {
1001 omi = objects.find(obj_class);
1002 if(omi != objects.end()) {
1003 std::set<std::string>::const_iterator i = omi->second.find(obj_id);
1004
1005 if(i != omi->second.end()) {
1006 conffwk::ConfigurationChange::add(changes, obj_class, obj_id, action);
1007 }
1008 }
1009 }
1010
1011
1012 // process the class
1013
1014 if(action == '+' || omi == objects.end()) {
1015 if(any || class_names.find(obj_class) != class_names.end()) {
1016 conffwk::ConfigurationChange::add(changes, obj_class, obj_id, action);
1017 }
1018 }
1019
1020
1021 // process subclasses
1022
1023 OksConfiguration::SMap::const_iterator it = inheritance.data().find(obj_class);
1024 if(it != inheritance.data().end()) {
1025 for(std::set<std::string>::const_iterator j = it->second.begin(); j != it->second.end(); ++j) {
1026 omi = (action != '+' ? objects.find(*j) : objects.end());
1027
1028 // 1. add objects if criteria is 'any'
1029 // 2. add object of class which has subscription and has no explicit object subscription
1030 // 3. add explicitly subscribed object
1031
1032 if(
1033 any ||
1034 (
1035 omi == objects.end() &&
1036 class_names.find(*j) != class_names.end()
1037 ) ||
1038 (
1039 omi != objects.end() &&
1040 omi->second.find(obj_id) != omi->second.end()
1041 )
1042 ) {
1043 conffwk::ConfigurationChange::add(changes, *j, obj_id, action);
1044 }
1045 }
1046 }
1047}
static void add(std::vector< ConfigurationChange * > &changes, const std::string &class_name, const std::string &obj_id, const char action)
Helper method to add object to the vector of existing changes.
const OksConfiguration::SMap & data() const

◆ is_repo_name()

bool is_repo_name ( const std::string & name)

Definition at line 109 of file OksConfiguration.cpp.

110{
111 if (!OksKernel::get_repository_root().empty())
112 {
113 std::string s(name);
114
116
117 bool is_absolute_path = (s[0] == '/');
118
119 if (!is_absolute_path)
120 s = std::string(OksKernel::get_cwd()) + '/' + s;
121
122 // if file system path exists
123 if (Oks::real_path(s, true))
124 {
126 return true;
127
128 static std::string user_repo_dir;
129 static std::once_flag flag;
130
131 std::call_once(flag, []()
132 {
133 if (const char * s = getenv("TDAQ_DB_USER_REPOSITORY"))
134 {
135 user_repo_dir = s;
136
137 try
138 {
139 Oks::real_path(user_repo_dir, false);
140 }
141 catch(oks::exception& ex)
142 {
143 TLOG_DEBUG( 0) << "Failed to read TDAQ_DB_USER_REPOSITORY = \'" << s << "\':\n\tcaused by: " << ex.what() ;
144 }
145 }
146 }
147 );
148
149 if (!user_repo_dir.empty() && s.find(user_repo_dir) == 0)
150 return true;
151
152 return false;
153 }
154 else
155 return true;
156 }
157
158 return false;
159}
static const std::string & get_repository_mapping_dir()
Get OKS repository name.
Definition kernel.cpp:355
static const std::string & get_repository_root()
Get OKS repository root.
Definition kernel.cpp:309
static const char * get_cwd()
Definition kernel.cpp:694
static void substitute_variables(std::string &)
Definition kernel.cpp:575
static bool real_path(std::string &, bool ignore_errors)
Definition kernel.cpp:599
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112

◆ mk_add_include_error_text()

std::string mk_add_include_error_text ( const std::string & db,
const std::string & include,
const char * error = nullptr )
static

Definition at line 336 of file OksConfiguration.cpp.

337{
338 std::ostringstream text;
339 text << "cannot add and load include file \'" << include << "\' to \'" << db << '\'';
340 if (error)
341 text << ":\n" << error;
342 return text.str();
343}
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34

◆ mk_no_file_error_text()

std::string mk_no_file_error_text ( const std::string & db)
static

Definition at line 328 of file OksConfiguration.cpp.

329{
330 std::ostringstream text;
331 text << "cannot find file \'" << db << '\'';
332 return text.str();
333}

◆ mk_rm_include_error_text()

std::string mk_rm_include_error_text ( const std::string & db,
const std::string & include,
const char * error = 0 )
static

Definition at line 1147 of file OksConfiguration.cpp.

1148{
1149 std::ostringstream text;
1150 text << "cannot remove include file \'" << include << "\' from \'" << db << '\'';
1151 if (error)
1152 text << ":\n" << error;
1153 return text.str();
1154}

◆ throw_update_exception()

void throw_update_exception ( const OksFile * file_h,
const char * action,
const char * reason )
static

Definition at line 364 of file OksConfiguration.cpp.

365{
366 std::ostringstream text;
367 text << "cannot " << action << " file \'" << file_h->get_full_file_name() << "\' since " << reason;
368 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
369}
const std::string & get_full_file_name() const
Definition file.hpp:528
std::string const reason(ers::Issue const &)