LCOV - code coverage report
Current view: top level - oksconflibs/src - OksConfigObject.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 21.4 % 515 110
Test Date: 2026-07-12 15:23:06 Functions: 23.0 % 122 28

            Line data    Source code
       1              : //
       2              : // DUNE DAQ modification notice:
       3              : // This file has been modified from the original ATLAS oksconfig source for the DUNE DAQ project.
       4              : // Fork baseline commit: oksconfig-03-02-00 (2021-04-20).
       5              : // Renamed since fork: no.
       6              : //
       7              : 
       8              : #include "ers/ers.hpp"
       9              : 
      10              : #include "oks/file.hpp"
      11              : #include "oks/relationship.hpp"
      12              : 
      13              : #include "conffwk/ConfigObject.hpp"
      14              : 
      15              : #include "oksconflibs/OksConfigObject.hpp"
      16              : #include "oksconflibs/OksConfiguration.hpp"
      17              : 
      18              : #include "logging/Logging.hpp"
      19              : 
      20              : using namespace dunedaq;
      21              : using namespace dunedaq::oks;
      22              : using namespace dunedaq::oksconflibs;
      23              : 
      24              : static std::string
      25            0 : mk_error_text(const char *op, const char * what, const std::string& name, const OksObject * o, const char * error)
      26              : {
      27            0 :   std::ostringstream text;
      28            0 :   text << "failed to " << op << ' ' << what << " \"" << name << "\" of object " << o;
      29            0 :   if (error)
      30            0 :     text << ": " << error;
      31            0 :   return text.str();
      32            0 : }
      33              : 
      34              : static std::string
      35            0 : mk_get_error_text(const char * what, const std::string& name, const OksObject * o, const char * error = nullptr)
      36              : {
      37            0 :   return mk_error_text("read", what, name, o, error);
      38              : }
      39              : 
      40              : static std::string
      41            0 : mk_set_error_text(const char * what, const std::string& name, const OksObject * o, const char * error = nullptr)
      42              : {
      43            0 :   return mk_error_text("set value", what, name, o, error);
      44              : }
      45              : 
      46              : 
      47              : OksData::Type
      48            0 : OksConfigObject::get_type(const std::string& name) const
      49              : {
      50            0 :   try
      51              :     {
      52            0 :       return m_obj->GetAttributeValue(name)->type;
      53              :     }
      54            0 :   catch (oks::exception& ex)
      55              :     {
      56            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
      57            0 :     }
      58              : }
      59              : 
      60              : // helper function to extract value out of OKS database
      61              : template<class T>
      62              :   void
      63         1448 :   OksConfigObject::get_value(const std::string& name, T& value)
      64              :   {
      65         1448 :     std::lock_guard<std::mutex> scoped_lock(m_mutex);
      66              : 
      67              :     try
      68              :       {
      69         1448 :         throw_if_deleted();
      70         1448 :         OksData * data(m_obj->GetAttributeValue(name));
      71         1448 :         value = *reinterpret_cast<T*>(&data->data); // really ugly stuff here, but should come out right
      72              :       }
      73            0 :     catch (oks::exception& ex)
      74              :       {
      75            0 :         throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
      76              :       }
      77         1448 :   }
      78              : 
      79              : 
      80              : // helper function to extract vector of values out of OKS database
      81              : template<class T>
      82              :   void
      83            0 :   OksConfigObject::get_vector(const std::string& name, std::vector<T>& value)
      84              :   {
      85            0 :     OksData * data = 0;
      86              : 
      87            0 :     std::lock_guard<std::mutex> scoped_lock(m_mutex);
      88              : 
      89              :     try
      90              :       {
      91            0 :         throw_if_deleted();
      92            0 :         data = m_obj->GetAttributeValue(name);
      93              :       }
      94            0 :     catch (oks::exception& ex)
      95              :       {
      96            0 :         throw dunedaq::conffwk::Generic( ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
      97              :       }
      98              : 
      99            0 :     if (data->type != OksData::list_type)
     100              :       {
     101            0 :         std::ostringstream text;
     102            0 :         text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
     103            0 :         throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
     104            0 :       }
     105              : 
     106            0 :     value.clear();
     107            0 :     for (const auto& it : *data->data.LIST)
     108              :       {
     109            0 :         value.push_back(*reinterpret_cast<T*>(&it->data));
     110              :       }
     111            0 :   }
     112              : 
     113              : 
     114         1229 : OksConfigObject::OksConfigObject(OksObject *obj, dunedaq::conffwk::ConfigurationImpl * impl) noexcept :
     115              :   ConfigObjectImpl (impl, obj->GetId()),
     116         1229 :   m_obj            (obj)
     117              : {
     118         1229 : }
     119              : 
     120         2458 : OksConfigObject::~OksConfigObject() noexcept
     121              : {
     122         2458 : }
     123              : 
     124              : const std::string
     125            0 : OksConfigObject::contained_in() const
     126              : {
     127            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     128            0 :   throw_if_deleted();
     129            0 :   return m_obj->get_file()->get_full_file_name();
     130            0 : }
     131              : 
     132              : void
     133           75 : OksConfigObject::get(const std::string& name, bool& value)
     134              : {
     135           75 :   get_value(name, value);
     136           75 : }
     137              : 
     138              : void
     139            8 : OksConfigObject::get(const std::string& name, uint8_t& value)
     140              : {
     141            8 :   get_value(name, value);
     142            8 : }
     143              : 
     144              : void
     145            0 : OksConfigObject::get(const std::string& name, int8_t& value)
     146              : {
     147            0 :   get_value(name, value);
     148            0 : }
     149              : 
     150              : void
     151           37 : OksConfigObject::get(const std::string& name, uint16_t& value)
     152              : {
     153           37 :   get_value(name, value);
     154           37 : }
     155              : 
     156              : void
     157            0 : OksConfigObject::get(const std::string& name, int16_t& value)
     158              : {
     159            0 :   get_value(name, value);
     160            0 : }
     161              : 
     162              : void
     163         1235 : OksConfigObject::get(const std::string& name, uint32_t& value)
     164              : {
     165         1235 :   get_value(name, value);
     166         1235 : }
     167              : 
     168              : void
     169           85 : OksConfigObject::get(const std::string& name, int32_t& value)
     170              : {
     171           85 :   get_value(name, value);
     172           85 : }
     173              : 
     174              : void
     175            8 : OksConfigObject::get(const std::string& name, uint64_t& value)
     176              : {
     177            8 :   get_value(name, value);
     178            8 : }
     179              : 
     180              : void
     181            0 : OksConfigObject::get(const std::string& name, int64_t& value)
     182              : {
     183            0 :   get_value(name, value);
     184            0 : }
     185              : 
     186              : void
     187            0 : OksConfigObject::get(const std::string& name, float& value)
     188              : {
     189            0 :   get_value(name, value);
     190            0 : }
     191              : 
     192              : void
     193            0 : OksConfigObject::get(const std::string& name, double& value)
     194              : {
     195            0 :   get_value(name, value);
     196            0 : }
     197              : 
     198              : void
     199         1090 : OksConfigObject::get(const std::string& name, std::string& value)
     200              : {
     201         1090 :   OksData * data = 0;
     202              : 
     203         1090 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     204              : 
     205         1090 :   try
     206              :     {
     207         1090 :       throw_if_deleted();
     208         1090 :       data = m_obj->GetAttributeValue(name);
     209              :     }
     210            0 :   catch (oks::exception& ex)
     211              :     {
     212            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
     213            0 :     }
     214              : 
     215         1090 :   if ((data->type == OksData::string_type) || (data->type == OksData::enum_type))
     216              :     {
     217         1090 :       value = *data->data.STRING;
     218              :       return;
     219              :     }
     220            0 :   else if (data->type == OksData::date_type || data->type == OksData::time_type)
     221              :     {
     222            0 :       value = data->str();
     223            0 :       return;
     224              :     }
     225            0 :   else if (data->type == OksData::class_type)
     226              :     {
     227            0 :       value = data->data.CLASS->get_name();
     228              :       return;
     229              :     }
     230              :   else
     231              :     {
     232            0 :       std::ostringstream text;
     233            0 :       text << "read wrong attribute type instead of expected \'string\' for attribute \"" << name << "\" of object " << m_obj;
     234            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
     235            0 :     }
     236         1090 : }
     237              : 
     238              : void
     239          679 : OksConfigObject::get(const std::string& name, dunedaq::conffwk::ConfigObject& value)
     240              : {
     241          679 :   OksData * data = 0;
     242              : 
     243          679 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     244              : 
     245          679 :   try
     246              :     {
     247          679 :       throw_if_deleted();
     248          679 :       data = m_obj->GetRelationshipValue(name);
     249              :     }
     250            0 :   catch (oks::exception& ex)
     251              :     {
     252            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
     253            0 :     }
     254              : 
     255          679 :   if (data->type != OksData::object_type)
     256              :     {
     257            0 :       if (data->type == OksData::uid_type || data->type == OksData::uid2_type)
     258              :         {
     259            0 :           std::ostringstream text;
     260            0 :           text << "referenced object " << *data << " is not loaded";
     261            0 :           throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj, text.str().c_str()).c_str());
     262            0 :         }
     263              : 
     264            0 :       std::ostringstream text;
     265            0 :       text << "bad value of relationship \"" << name << "\" of object " << m_obj << ": ";
     266              : 
     267            0 :       if(data->type == OksData::list_type)
     268              :         {
     269            0 :           text << "the relationship is multi-value";
     270              :         }
     271              :       else
     272              :         {
     273            0 :           text << "non-object type was read";
     274              :         }
     275            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
     276            0 :     }
     277              : 
     278          679 :   if (data->data.OBJECT != nullptr)
     279              :     {
     280          611 :       value = static_cast<OksConfiguration *>(m_impl)->new_object(data->data.OBJECT);
     281              :     }
     282              :   else
     283              :     {
     284           68 :       value = nullptr;
     285              :     }
     286          679 : }
     287              : 
     288              : void
     289            0 : OksConfigObject::get(const std::string& name, std::vector<bool>& value)
     290              : {
     291            0 :   get_vector(name, value);
     292            0 : }
     293              : 
     294              : void
     295            0 : OksConfigObject::get(const std::string& name, std::vector<uint8_t>& value)
     296              : {
     297            0 :   get_vector(name, value);
     298            0 : }
     299              : 
     300              : void
     301            0 : OksConfigObject::get(const std::string& name, std::vector<int8_t>& value)
     302              : {
     303            0 :   get_vector(name, value);
     304            0 : }
     305              : 
     306              : void
     307            0 : OksConfigObject::get(const std::string& name, std::vector<uint16_t>& value)
     308              : {
     309            0 :   get_vector(name, value);
     310            0 : }
     311              : 
     312              : void
     313            0 : OksConfigObject::get(const std::string& name, std::vector<int16_t>& value)
     314              : {
     315            0 :   get_vector(name, value);
     316            0 : }
     317              : 
     318              : void
     319            0 : OksConfigObject::get(const std::string& name, std::vector<uint32_t>& value)
     320              : {
     321            0 :   get_vector(name, value);
     322            0 : }
     323              : 
     324              : void
     325            0 : OksConfigObject::get(const std::string& name, std::vector<int32_t>& value)
     326              : {
     327            0 :   get_vector(name, value);
     328            0 : }
     329              : 
     330              : void
     331            0 : OksConfigObject::get(const std::string& name, std::vector<uint64_t>& value)
     332              : {
     333            0 :   get_vector(name, value);
     334            0 : }
     335              : 
     336              : void
     337            0 : OksConfigObject::get(const std::string& name, std::vector<int64_t>& value)
     338              : {
     339            0 :   get_vector(name, value);
     340            0 : }
     341              : 
     342              : void
     343            0 : OksConfigObject::get(const std::string& name, std::vector<float>& value)
     344              : {
     345            0 :   get_vector(name, value);
     346            0 : }
     347              : 
     348              : void
     349            0 : OksConfigObject::get(const std::string& name, std::vector<double>& value)
     350              : {
     351            0 :   get_vector(name, value);
     352            0 : }
     353              : 
     354              : void
     355           61 : OksConfigObject::get(const std::string& name, std::vector<std::string>& value)
     356              : {
     357           61 :   OksData * data = 0;
     358              : 
     359           61 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     360              : 
     361           61 :   try
     362              :     {
     363           61 :       throw_if_deleted();
     364           61 :       data = m_obj->GetAttributeValue(name);
     365              :     }
     366            0 :   catch (oks::exception& ex)
     367              :     {
     368            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
     369            0 :     }
     370              : 
     371           61 :   if (data->type != OksData::list_type)
     372              :     {
     373            0 :       std::ostringstream text;
     374            0 :       text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
     375            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
     376            0 :     }
     377              : 
     378           61 :   value.clear();
     379              : 
     380           76 :   for (const auto & it : *data->data.LIST)
     381              :     {
     382           15 :       if ((it->type == OksData::string_type) || (it->type == OksData::enum_type))
     383              :         {
     384            0 :           value.emplace_back(*it->data.STRING);
     385              :         }
     386           15 :       else if (it->type == OksData::class_type)
     387              :         {
     388           15 :           value.emplace_back(it->data.CLASS->get_name());
     389              :         }
     390            0 :       else if (it->type == OksData::date_type || it->type == OksData::time_type)
     391              :         {
     392            0 :           value.emplace_back(it->str());
     393              :         }
     394              :       else
     395              :         {
     396            0 :           std::ostringstream text;
     397            0 :           text << "wrong type of attribute \"" << name << "\" of object " << m_obj << " (instead of expected string)";
     398            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
     399            0 :         }
     400              :     }
     401           61 : }
     402              : 
     403              : 
     404              : void
     405          663 : OksConfigObject::get(const std::string& name, std::vector<dunedaq::conffwk::ConfigObject>& value)
     406              : {
     407          663 :   OksData * data = 0;
     408              : 
     409          663 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     410              : 
     411          663 :   try
     412              :     {
     413          663 :       throw_if_deleted();
     414          663 :       data = m_obj->GetRelationshipValue(name);
     415              :     }
     416            0 :   catch (oks::exception& ex)
     417              :     {
     418            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
     419            0 :     }
     420              : 
     421          663 :   if (data->type != OksData::list_type)
     422              :     {
     423            0 :       std::ostringstream text;
     424            0 :       text << "the value of relationship \"" << name << "\" of object " << m_obj << " is not multi-value";
     425            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
     426            0 :     }
     427              : 
     428          663 :   value.clear();
     429              : 
     430         1141 :   for (const auto& it : *data->data.LIST)
     431              :     {
     432          478 :       if (it->type != OksData::object_type)
     433              :         {
     434            0 :           TLOG_DEBUG(1) <<  "object " << *it << " is not loaded (relationship \'" << name << "\' of object " << m_obj << ')' ;
     435              :         }
     436          478 :       else if (!it->data.OBJECT)
     437              :         {
     438            0 :           TLOG_DEBUG(1) <<  "skip (null) object in relationship \'" << name << "\' of object " << m_obj ;
     439              :         }
     440              :       else
     441              :         {
     442          478 :           value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(it->data.OBJECT)));
     443              :         }
     444              :     }
     445          663 : }
     446              : 
     447              : bool
     448            0 : OksConfigObject::rel(const std::string& name, std::vector<conffwk::ConfigObject>& value)
     449              : {
     450            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     451              : 
     452            0 :   try
     453              :     {
     454            0 :       throw_if_deleted();
     455              : 
     456            0 :       if (OksDataInfo * di = m_obj->GetClass()->get_data_info(name))
     457              :         {
     458            0 :           if (di->relationship)
     459              :             {
     460            0 :               OksData * data = m_obj->GetRelationshipValue(di);
     461              : 
     462            0 :               if (data->type == OksData::object_type)
     463              :                 {
     464            0 :                   if (data->data.OBJECT != nullptr)
     465              :                     {
     466            0 :                       value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(data->data.OBJECT)));
     467              :                     }
     468              :                 }
     469            0 :               else if (data->type == OksData::list_type)
     470              :                 {
     471            0 :                   for (const auto& it : *data->data.LIST)
     472              :                     {
     473            0 :                       if (it->type == OksData::object_type)
     474              :                         {
     475            0 :                           value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(it->data.OBJECT)));
     476              :                         }
     477              :                     }
     478              :                 }
     479              : 
     480            0 :               return true;
     481              :             }
     482              :         }
     483              : 
     484              :       return false;
     485              :     }
     486            0 :   catch (oks::exception& ex)
     487              :     {
     488            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
     489            0 :     }
     490            0 : }
     491              : 
     492              : void
     493            0 : OksConfigObject::referenced_by(std::vector<conffwk::ConfigObject>& value, const std::string& rname, bool check_composite_only, unsigned long /* rlevel */, const std::vector<std::string> * /* rclasses */) const
     494              : {
     495            0 :   value.clear();
     496              : 
     497            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     498            0 :   throw_if_deleted();
     499              : 
     500            0 :   if (check_composite_only)
     501              :     {
     502            0 :       bool any_name = (rname == "*");
     503              : 
     504            0 :       if (const std::list<OksRCR *> * rcr = m_obj->reverse_composite_rels())
     505              :         {
     506            0 :           for (const auto& i : *rcr)
     507              :             {
     508            0 :               if (any_name || rname == i->relationship->get_name())
     509              :                 {
     510            0 :                   value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(i->obj)));
     511              :                 }
     512              :             }
     513              :         }
     514              :     }
     515              :   else
     516              :     {
     517            0 :       if (OksObject::FList * objs = m_obj->get_all_rels(rname))
     518              :         {
     519            0 :           for (const auto& i : *objs)
     520              :             {
     521            0 :               value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(i)));
     522              :             }
     523              : 
     524            0 :           delete objs;
     525              :         }
     526              :     }
     527            0 : }
     528              : 
     529              :    /////////////////////////////////////////////////////////////////////////////
     530              :    //
     531              :    //  set functions
     532              :    //
     533              :    /////////////////////////////////////////////////////////////////////////////
     534              : 
     535              : void
     536           11 : OksConfigObject::set_attr_value(const std::string& name, OksData & data)
     537              : {
     538           11 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     539              : 
     540           11 :   try
     541              :     {
     542           11 :       throw_if_deleted();
     543              :       //test_checkout_needs();
     544           11 :       m_obj->SetAttributeValue(name, &data);
     545              :     }
     546            0 :   catch (dunedaq::conffwk::Generic& ex)
     547              :     {
     548            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     549            0 :     }
     550            0 :   catch(oks::exception& ex)
     551              :     {
     552            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     553            0 :     }
     554           11 : }
     555              : 
     556              : void
     557           10 : OksConfigObject::set_rel_value(const std::string& name, OksData & data, bool skip_non_null_check)
     558              : {
     559           10 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     560              : 
     561           10 :   try
     562              :     {
     563           10 :       throw_if_deleted();
     564              :       //test_checkout_needs();
     565           10 :       m_obj->SetRelationshipValue(name, &data, skip_non_null_check);
     566              :     }
     567            0 :   catch (dunedaq::conffwk::Generic& ex)
     568              :     {
     569            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex );
     570            0 :     }
     571            0 :   catch(oks::exception& ex)
     572              :     {
     573            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex);
     574            0 :     }
     575           10 : }
     576              : 
     577              : 
     578              : template<class T>
     579              :   void
     580           11 :   OksConfigObject::set_value(const std::string& name, const T& value)
     581              :   {
     582           11 :     OksData d(value);
     583           11 :     set_attr_value(name, d);
     584           11 :   }
     585              : 
     586              : template<class T>
     587              :   void
     588            0 :   OksConfigObject::set_vector(const std::string& name, const std::vector<T>& value)
     589              :   {
     590            0 :     OksData d(new OksData::List());
     591              : 
     592            0 :     for (const auto& i : value)
     593              :       {
     594            0 :         d.data.LIST->push_back(new OksData(i));
     595              :       }
     596              : 
     597            0 :     set_attr_value(name, d);
     598            0 :   }
     599              : 
     600              : 
     601            0 : void OksConfigObject::set(const std::string& name, bool value)
     602              : {
     603            0 :   set_value(name, value);
     604            0 : }
     605              : 
     606            0 : void OksConfigObject::set(const std::string& name, uint8_t value)
     607              : {
     608            0 :   set_value(name, value);
     609            0 : }
     610              : 
     611            0 : void OksConfigObject::set(const std::string& name, int8_t value)
     612              : {
     613            0 :   set_value(name, value);
     614            0 : }
     615              : 
     616            0 : void OksConfigObject::set(const std::string& name, uint16_t value)
     617              : {
     618            0 :   set_value(name, value);
     619            0 : }
     620              : 
     621            0 : void OksConfigObject::set(const std::string& name, int16_t value)
     622              : {
     623            0 :   set_value(name, value);
     624            0 : }
     625              : 
     626            0 : void OksConfigObject::set(const std::string& name, uint32_t value)
     627              : {
     628            0 :   set_value(name, value);
     629            0 : }
     630              : 
     631            2 : void OksConfigObject::set(const std::string& name, int32_t value)
     632              : {
     633            2 :   set_value(name, value);
     634            2 : }
     635              : 
     636            1 : void OksConfigObject::set(const std::string& name, uint64_t value)
     637              : {
     638            1 :   set_value(name, value);
     639            1 : }
     640              : 
     641            0 : void OksConfigObject::set(const std::string& name, int64_t value)
     642              : {
     643            0 :   set_value(name, value);
     644            0 : }
     645              : 
     646            0 : void OksConfigObject::set(const std::string& name, float value)
     647              : {
     648            0 :   set_value(name, value);
     649            0 : }
     650              : 
     651            0 : void OksConfigObject::set(const std::string& name, double value)
     652              : {
     653            0 :   set_value(name, value);
     654            0 : }
     655              : 
     656            8 : void OksConfigObject::set(const std::string& name, const std::string& value)
     657              : {
     658            8 :   set_value(name, value);
     659            8 : }
     660              : 
     661              : void
     662            0 : OksConfigObject::set_enum(const std::string& name, const std::string& value)
     663              : {
     664            0 :   OksData d;
     665              : 
     666            0 :     {
     667            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     668            0 :       throw_if_deleted();
     669              : 
     670            0 :       if (OksAttribute * a = m_obj->GetClass()->find_attribute(name))
     671              :         {
     672            0 :           try
     673              :             {
     674            0 :               d.data.ENUMERATION = a->get_enum_value(value);
     675            0 :               d.type = OksData::enum_type;
     676              :             }
     677            0 :           catch (std::exception& ex)
     678              :             {
     679            0 :               throw(dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, ex.what()).c_str()) );
     680            0 :             }
     681              :         }
     682              :       else
     683              :         {
     684            0 :           throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str()) );
     685              :         }
     686            0 :     }
     687              : 
     688            0 :   set_attr_value(name, d);
     689            0 : }
     690              : 
     691            0 : void OksConfigObject::set_class(const std::string& name, const std::string& value)
     692              : {
     693            0 :   OksData d;
     694              : 
     695            0 :   d.data.CLASS = nullptr;
     696            0 :   d.type = OksData::class_type;
     697              : 
     698              :     // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
     699            0 :     {
     700            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     701            0 :       throw_if_deleted();
     702              : 
     703            0 :       const std::list<OksAttribute *> * attrs = m_obj->GetClass()->all_attributes();
     704              : 
     705            0 :       if (!attrs || attrs->empty())
     706              :         {
     707            0 :           throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
     708              :         }
     709              : 
     710            0 :       try
     711              :         {
     712            0 :           d.SetValue(value.c_str(), attrs->front());
     713              :         }
     714            0 :       catch (oks::exception & ex)
     715              :         {
     716            0 :           throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     717            0 :         }
     718            0 :     }
     719              : 
     720            0 :   set_attr_value(name, d);
     721            0 : }
     722              : 
     723              : void
     724            0 : OksConfigObject::set_date(const std::string& name, const std::string& value)
     725              : {
     726            0 :   OksData d;
     727            0 :   d.type = OksData::date_type;
     728              : 
     729            0 :   try
     730              :     {
     731            0 :       d.SetValue(value.c_str(), nullptr);
     732              :     }
     733            0 :   catch (oks::exception& ex)
     734              :     {
     735            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     736            0 :     }
     737              : 
     738            0 :   set_attr_value(name, d);
     739            0 : }
     740              : 
     741              : void
     742            0 : OksConfigObject::set_time(const std::string& name, const std::string& value)
     743              : {
     744            0 :   OksData d;
     745            0 :   d.type = OksData::time_type;
     746              : 
     747            0 :   try
     748              :     {
     749            0 :       d.SetValue(value.c_str(), nullptr);
     750              :     }
     751            0 :   catch (oks::exception& ex)
     752              :     {
     753            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     754            0 :     }
     755              : 
     756            0 :   set_attr_value(name, d);
     757            0 : }
     758              : 
     759              : 
     760              : void
     761            0 : OksConfigObject::set(const std::string& name, const std::vector<bool>& value)
     762              : {
     763            0 :   set_vector(name, value);
     764            0 : }
     765              : 
     766              : void
     767            0 : OksConfigObject::set(const std::string& name, const std::vector<uint8_t>& value)
     768              : {
     769            0 :   set_vector(name, value);
     770            0 : }
     771              : 
     772              : void
     773            0 : OksConfigObject::set(const std::string& name, const std::vector<int8_t>& value)
     774              : {
     775            0 :   set_vector(name, value);
     776            0 : }
     777              : 
     778              : void
     779            0 : OksConfigObject::set(const std::string& name, const std::vector<uint16_t>& value)
     780              : {
     781            0 :   set_vector(name, value);
     782            0 : }
     783              : 
     784              : void
     785            0 : OksConfigObject::set(const std::string& name, const std::vector<int16_t>& value)
     786              : {
     787            0 :   set_vector(name, value);
     788            0 : }
     789              : 
     790              : void
     791            0 : OksConfigObject::set(const std::string& name, const std::vector<uint32_t>& value)
     792              : {
     793            0 :   set_vector(name, value);
     794            0 : }
     795              : 
     796              : void
     797            0 : OksConfigObject::set(const std::string& name, const std::vector<int32_t>& value)
     798              : {
     799            0 :   set_vector(name, value);
     800            0 : }
     801              : 
     802              : void
     803            0 : OksConfigObject::set(const std::string& name, const std::vector<uint64_t>& value)
     804              : {
     805            0 :   set_vector(name, value);
     806            0 : }
     807              : 
     808              : void
     809            0 : OksConfigObject::set(const std::string& name, const std::vector<int64_t>& value)
     810              : {
     811            0 :   set_vector(name, value);
     812            0 : }
     813              : 
     814              : void
     815            0 : OksConfigObject::set(const std::string& name, const std::vector<float>& value)
     816              : {
     817            0 :   set_vector(name, value);
     818            0 : }
     819              : 
     820              : void
     821            0 : OksConfigObject::set(const std::string& name, const std::vector<double>& value)
     822              : {
     823            0 :   set_vector(name, value);
     824            0 : }
     825              : 
     826              : void
     827            0 : OksConfigObject::set(const std::string& name, const std::vector<std::string>& value)
     828              : {
     829            0 :   set_vector(name, value);
     830            0 : }
     831              : 
     832              : void
     833            0 : OksConfigObject::set_enum(const std::string& name, const std::vector<std::string>& value)
     834              : {
     835            0 :   OksData d(new OksData::List());
     836              : 
     837            0 :     {
     838            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     839            0 :       throw_if_deleted();
     840              : 
     841            0 :       if (OksAttribute * a = m_obj->GetClass()->find_attribute(name))
     842              :         {
     843            0 :           for (const auto& i : value)
     844              :             {
     845            0 :               OksData * d2 = new OksData();
     846            0 :               try
     847              :                 {
     848            0 :                   d2->data.ENUMERATION = a->get_enum_value(i); // new OksString(i);
     849            0 :                   d2->type = OksData::enum_type;
     850            0 :                   d.data.LIST->push_back(d2);
     851              :                 }
     852            0 :               catch (std::exception& ex)
     853              :                 {
     854            0 :                   throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     855            0 :                 }
     856              : 
     857              :             }
     858              :         }
     859              :       else
     860              :         {
     861            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
     862              :         }
     863            0 :     }
     864              : 
     865            0 :   set_attr_value(name, d);
     866            0 : }
     867              : 
     868              : void
     869            0 : OksConfigObject::set_class(const std::string& name, const std::vector<std::string>& value)
     870              : {
     871            0 :   OksData d(new OksData::List());
     872              : 
     873              :   // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
     874              : 
     875            0 :     {
     876            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     877            0 :       throw_if_deleted();
     878              : 
     879            0 :       const std::list<OksAttribute *> * attrs = m_obj->GetClass()->all_attributes();
     880              : 
     881            0 :       if (!attrs || attrs->empty())
     882              :         {
     883            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
     884              :         }
     885              : 
     886            0 :       for (const auto& i : value)
     887              :         {
     888            0 :           OksData * d2 = new OksData();
     889            0 :           d2->data.CLASS = 0;
     890            0 :           d2->type = OksData::class_type;
     891              : 
     892            0 :           try
     893              :             {
     894            0 :               d2->SetValue(i.c_str(), attrs->front());
     895              :             }
     896            0 :           catch (oks::exception & ex)
     897              :             {
     898            0 :               throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     899            0 :             }
     900              : 
     901            0 :           d.data.LIST->push_back(d2);
     902              :         }
     903            0 :     }
     904              : 
     905            0 :   set_attr_value(name, d);
     906            0 : }
     907              : 
     908              : void
     909            0 : OksConfigObject::set_date(const std::string& name, const std::vector<std::string>& value)
     910              : {
     911            0 :   OksData d(new OksData::List());
     912              : 
     913            0 :   for (const auto& i : value)
     914              :     {
     915            0 :       OksData * d2 = new OksData();
     916            0 :       d2->type = OksData::date_type;
     917            0 :       try
     918              :         {
     919            0 :           d2->SetValue(i.c_str(), nullptr);
     920              :         }
     921            0 :       catch (oks::exception& ex)
     922              :         {
     923            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     924            0 :         }
     925            0 :       d.data.LIST->push_back(d2);
     926              :     }
     927              : 
     928            0 :   set_attr_value(name, d);
     929            0 : }
     930              : 
     931              : void
     932            0 : OksConfigObject::set_time(const std::string& name, const std::vector<std::string>& value)
     933              : {
     934            0 :   OksData d(new OksData::List());
     935              : 
     936            0 :   for (const auto& i : value)
     937              :     {
     938            0 :       OksData * d2 = new OksData();
     939            0 :       d2->type = OksData::time_type;
     940            0 :       try
     941              :         {
     942            0 :           d2->SetValue(i.c_str(), 0);
     943              :         }
     944            0 :       catch (oks::exception& ex)
     945              :         {
     946            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     947            0 :         }
     948            0 :       d.data.LIST->push_back(d2);
     949              :     }
     950              : 
     951            0 :   set_attr_value(name, d);
     952            0 : }
     953              : 
     954              : void
     955            1 : OksConfigObject::set(const std::string& name, const conffwk::ConfigObject * value, bool skip_non_null_check)
     956              : {
     957            1 :   OksData d((value != nullptr) ? static_cast<const OksConfigObject*>(value->implementation())->m_obj : (OksObject *) nullptr);
     958            1 :   set_rel_value(name, d, skip_non_null_check);
     959            1 : }
     960              : 
     961              : void
     962            9 : OksConfigObject::set(const std::string& name, const std::vector<const conffwk::ConfigObject*>& value, bool skip_non_null_check)
     963              : {
     964            9 :   OksData d(new OksData::List());
     965              : 
     966           30 :   for (const auto& i : value)
     967              :     {
     968           21 :       d.data.LIST->push_back(new OksData(static_cast<const OksConfigObject*>(i->implementation())->m_obj));
     969              :     }
     970              : 
     971            9 :   set_rel_value(name, d, skip_non_null_check);
     972            9 : }
     973              : 
     974              : //void OksConfigObject::test_checkout_needs()
     975              : //{
     976              : ////  static_cast<OksConfiguration *>(m_impl)->test_and_checkout(m_obj->get_file());
     977              : //}
     978              : 
     979              : void
     980            0 : OksConfigObject::move(const std::string& at)
     981              : {
     982            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     983              : 
     984            0 :   throw_if_deleted();
     985              : 
     986            0 :   if (OksFile * new_file_h = m_obj->GetClass()->get_kernel()->find_data_file(at))
     987              :     {
     988            0 :       OksFile * old_file_h = m_obj->get_file();
     989            0 :       if (old_file_h != new_file_h)
     990              :         {
     991            0 :           try
     992              :             {
     993              : //              static_cast<OksConfiguration *>(m_impl)->test_and_checkout(old_file_h);
     994              : //              static_cast<OksConfiguration *>(m_impl)->test_and_checkout(new_file_h);
     995            0 :               m_obj->set_file(new_file_h, false);
     996              :             }
     997            0 :           catch (oks::exception& ex)
     998              :             {
     999            0 :               throw dunedaq::conffwk::Generic(ERS_HERE, ex.what());
    1000            0 :             }
    1001              :         }
    1002              :     }
    1003              :   else
    1004              :     {
    1005            0 :       std::ostringstream text;
    1006            0 :       text << "file \"" << at << "\" is not loaded";
    1007            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
    1008            0 :     }
    1009            0 : }
    1010              : 
    1011              : 
    1012              : void
    1013            0 : OksConfigObject::rename(const std::string& new_id)
    1014              : {
    1015            0 :   try
    1016              :     {
    1017            0 :       throw_if_deleted();
    1018              : 
    1019              : //      std::set<OksFile *> files;
    1020              : //
    1021              : //      files.insert(m_obj->get_file());
    1022              : //
    1023              : //      if (OksObject::FList * objs = m_obj->get_all_rels())
    1024              : //        {
    1025              : //          for (auto & f : *objs)
    1026              : //            {
    1027              : //              files.insert(f->get_file());
    1028              : //            }
    1029              : //
    1030              : //          delete objs;
    1031              : //        }
    1032              : //
    1033              : //      for (auto & f : files)
    1034              : //        {
    1035              : //          static_cast<OksConfiguration *>(m_impl)->test_and_checkout(f);
    1036              : //        }
    1037              : 
    1038            0 :       m_obj->set_id(new_id);
    1039              :     }
    1040            0 :   catch (oks::exception& ex)
    1041              :     {
    1042            0 :       std::ostringstream text;
    1043            0 :       text << "cannot rename object " << m_obj << " to new name \'" << new_id << "\' because " << ex.what();
    1044            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
    1045            0 :     }
    1046            0 : }
    1047              : 
    1048              : void
    1049            0 : OksConfigObject::reset()
    1050              : {
    1051            0 :   if (OksClass * c = static_cast<OksConfiguration *>(m_impl)->m_kernel->find_class(*m_class_name))
    1052              :     {
    1053            0 :       m_obj = c->get_object(m_id);
    1054              :     }
    1055              :   else
    1056              :     {
    1057            0 :       m_obj = nullptr;
    1058              :     }
    1059              : 
    1060            0 :   m_state = (m_obj ? dunedaq::conffwk::Valid : dunedaq::conffwk::Deleted);
    1061            0 : }
        

Generated by: LCOV version 2.0-1