DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::OksRange Class Reference

OKS range class. More...

#include <attribute.hpp>

Public Member Functions

 OksRange (const std::string &range, OksAttribute *a)
 
void reset (const std::string &range, OksAttribute *a)
 
bool validate (const OksData &) const
 
bool is_empty ()
 

Private Member Functions

void clear ()
 

Private Attributes

std::string m_range
 
std::list< OksDatam_less
 
std::list< OksDatam_equal
 
std::list< std::pair< OksData, OksData > > m_interval
 
std::list< OksDatam_great
 
std::list< boost::regex > m_like
 

Detailed Description

OKS range class.

The OksRange class implements OKS range that can be defined for an OKS attribute. The range is a set of list of conditions using UML syntax. For string types the range is a regular expression.

Definition at line 41 of file attribute.hpp.

Constructor & Destructor Documentation

◆ OksRange()

dunedaq::oks::OksRange::OksRange ( const std::string & range,
OksAttribute * a )
inline

Definition at line 45 of file attribute.hpp.

46 {
47 reset(range, a);
48 }
void reset(const std::string &range, OksAttribute *a)
DAC value out of range
Message.
Definition DACNode.hpp:32

Member Function Documentation

◆ clear()

void dunedaq::oks::OksRange::clear ( )
inlineprivate

Definition at line 75 of file attribute.hpp.

76 {
77 m_range.clear();
78
79 m_less.clear();
80 m_equal.clear();
81 m_interval.clear();
82 m_great.clear();
83 m_like.clear();
84 }
std::list< std::pair< OksData, OksData > > m_interval
Definition attribute.hpp:68
std::list< OksData > m_less
Definition attribute.hpp:66
std::list< OksData > m_great
Definition attribute.hpp:69
std::list< boost::regex > m_like
Definition attribute.hpp:70
std::list< OksData > m_equal
Definition attribute.hpp:67

◆ is_empty()

bool dunedaq::oks::OksRange::is_empty ( )
inline

Definition at line 57 of file attribute.hpp.

58 {
59 return (m_less.empty() && m_equal.empty() && m_interval.empty() && m_great.empty() && m_like.empty());
60 }

◆ reset()

void dunedaq::oks::OksRange::reset ( const std::string & range,
OksAttribute * a )

Definition at line 839 of file attribute.cpp.

840{
841 clear();
842
843 if (a->get_data_type() != OksData::string_type)
844 {
845 if (!range.empty())
846 {
847 Oks::Tokenizer t(range, ",");
848 std::string token, token1, token2;
849
850 while (t.next(token))
851 {
852 if (is_star(token))
853 {
854 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
855 clear();
856 return;
857 }
858
859 static const char __dot_dot_str[] = "..";
860 std::string::size_type p = token.find(__dot_dot_str, 0, (sizeof(__dot_dot_str) - 1));
861
862 bool pi; // if true, then it is plus infinity, i.e. x..*
863
864 if (p != std::string::npos)
865 {
866 token1.assign(token, 0, p);
867 token2.assign(token, p + 2, std::string::npos);
868 pi = (is_star(token2));
869 }
870 else
871 {
872 token1.assign(token);
873 token2.clear();
874 pi = false;
875 }
876
877 bool mi = (is_star(token1)); // if true, then it is minus infinity, i.e. *..x
878
879 if (mi && pi)
880 {
881 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
882 clear();
883 return;
884 }
885
886 OksData d1, d2;
887
888 if (!mi)
889 {
890 d1.type = a->get_data_type();
891 d1.ReadFrom(token1, a);
892 }
893
894 if (token2.empty())
895 {
896 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines equality condition";
897 m_equal.emplace_back(d1);
898 }
899 else
900 {
901 if (!pi)
902 {
903 d2.type = a->get_data_type();
904 d2.ReadFrom(token2, a);
905 }
906
907 if (mi)
908 {
909 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines smaller condition";
910 m_less.emplace_back(d2);
911 }
912 else if (pi)
913 {
914 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines greater condition";
915 m_great.emplace_back(d1);
916 }
917 else
918 {
919 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines interval condition";
920 m_interval.emplace_back(d1, d2);
921 }
922 }
923 }
924 }
925 }
926 else
927 {
928 try
929 {
930 m_like.emplace_back(range);
931 }
932 catch (std::exception& ex)
933 {
934 throw BadReqExp(range, ex.what());
935 }
936 }
937}
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
bool is_star(const std::string &s)

◆ validate()

bool dunedaq::oks::OksRange::validate ( const OksData & d) const

Definition at line 940 of file attribute.cpp.

941{
942 for (const auto& x : m_less)
943 {
944 if (d <= x)
945 return true;
946 }
947
948 for (const auto& x : m_great)
949 {
950 if (d >= x)
951 return true;
952 }
953
954 for (const auto& x : m_equal)
955 {
956 if (d == x)
957 return true;
958 }
959
960 for (const auto& x : m_interval)
961 {
962 if (d >= x.first && d <= x.second)
963 return true;
964 }
965
966 for (const auto& x : m_like)
967 {
969 return true;
970
971 if (boost::regex_match(d.str(),x))
972 return true;
973 }
974
975 return false;
976}
static bool get_skip_string_range()
Get status of string range validator.
Definition kernel.hpp:799

Member Data Documentation

◆ m_equal

std::list<OksData> dunedaq::oks::OksRange::m_equal
private

Definition at line 67 of file attribute.hpp.

◆ m_great

std::list<OksData> dunedaq::oks::OksRange::m_great
private

Definition at line 69 of file attribute.hpp.

◆ m_interval

std::list<std::pair<OksData,OksData> > dunedaq::oks::OksRange::m_interval
private

Definition at line 68 of file attribute.hpp.

◆ m_less

std::list<OksData> dunedaq::oks::OksRange::m_less
private

Definition at line 66 of file attribute.hpp.

◆ m_like

std::list<boost::regex> dunedaq::oks::OksRange::m_like
private

Definition at line 70 of file attribute.hpp.

◆ m_range

std::string dunedaq::oks::OksRange::m_range
private

Definition at line 64 of file attribute.hpp.


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