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
 Including Qt Headers.
 
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 34 of file OksConfiguration.cpp.

34 {
35 try {
36 std::unique_ptr<OksConfiguration> impl(new OksConfiguration());
37 if(!spec.empty()) { impl->open_db(spec); }
38 return impl.release();
39 }
40 catch(dunedaq::conffwk::Exception & ex) {
41 throw dunedaq::conffwk::Generic(ERS_HERE, "oksconflibs initialization error", ex);
42 }
43 catch(...) {
44 throw dunedaq::conffwk::Generic(ERS_HERE, "oksconflibs initialization error:\n***** caught unknown exception *****");
45 }
46}
#define ERS_HERE
Generic configuration exception.

◆ check()

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

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

Definition at line 974 of file OksConfiguration.cpp.

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

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

◆ mk_add_include_error_text()

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

Definition at line 329 of file OksConfiguration.cpp.

330{
331 std::ostringstream text;
332 text << "cannot add and load include file \'" << include << "\' to \'" << db << '\'';
333 if (error)
334 text << ":\n" << error;
335 return text.str();
336}
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34

◆ mk_no_file_error_text()

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

Definition at line 321 of file OksConfiguration.cpp.

322{
323 std::ostringstream text;
324 text << "cannot find file \'" << db << '\'';
325 return text.str();
326}

◆ mk_rm_include_error_text()

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

Definition at line 1140 of file OksConfiguration.cpp.

1141{
1142 std::ostringstream text;
1143 text << "cannot remove include file \'" << include << "\' from \'" << db << '\'';
1144 if (error)
1145 text << ":\n" << error;
1146 return text.str();
1147}

◆ throw_update_exception()

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

Definition at line 357 of file OksConfiguration.cpp.

358{
359 std::ostringstream text;
360 text << "cannot " << action << " file \'" << file_h->get_full_file_name() << "\' since " << reason;
361 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
362}
const std::string & get_full_file_name() const
Definition file.hpp:523
std::string const reason(ers::Issue const &)