1 #include "otsdaq/TableCore/TableGroupKey.h"
3 #include "otsdaq/Macros/CoutMacros.h"
10 const unsigned int TableGroupKey::INVALID = -1;
11 const unsigned int TableGroupKey::DEFAULT = 0;
14 TableGroupKey::TableGroupKey(
unsigned int key) : key_(key) {}
18 TableGroupKey::TableGroupKey(
char*
const& groupString)
22 key_ = TableGroupKey::INVALID;
28 int i = strlen(groupString) - 1;
30 if((groupString[i] <
'0' || groupString[i] >
'9') && groupString[i] !=
'-' && groupString[i] !=
'_' && groupString[i] !=
'.')
33 if(i == (
int)strlen(groupString) - 1)
35 key_ = TableGroupKey::DEFAULT;
44 sscanf(&groupString[i],
"%u", &key_);
48 TableGroupKey::TableGroupKey(
const std::string& groupString) :
TableGroupKey((char*)groupString.c_str()) {}
51 TableGroupKey::~TableGroupKey(
void) {}
54 unsigned int TableGroupKey::key(
void)
const {
return key_; }
58 bool TableGroupKey::operator==(
unsigned int key)
const {
return (key_ == key); }
59 bool TableGroupKey::operator==(
const TableGroupKey& key)
const {
return (key_ == key.key_); }
63 std::string TableGroupKey::toString(
void)
const
66 return (isInvalid()) ? std::to_string((
int)key_) : std::to_string(key_);
71 TableGroupKey& TableGroupKey::operator=(
const unsigned int key)
78 bool TableGroupKey::operator!=(
unsigned int key)
const {
return (key_ != key); }
79 bool TableGroupKey::operator!=(
const TableGroupKey& key)
const {
return (key_ != key.key_); }
83 bool TableGroupKey::operator<(
const TableGroupKey& key)
const {
return (key_ < key.key_); }
87 bool TableGroupKey::operator>(
const TableGroupKey& key)
const {
return (key_ > key.key_); }
91 bool TableGroupKey::isInvalid()
const {
return (key_ == INVALID); }
106 unsigned int TableGroupKey::getDefaultKey(
void) {
return DEFAULT; }
109 unsigned int TableGroupKey::getInvalidKey(
void) {
return INVALID; }
117 std::string TableGroupKey::getFullGroupString(
const std::string& groupName,
const TableGroupKey& key)
119 if(groupName.size() == 0)
122 << (
"TableGroupKey::getFullGroupString() Illegal Group Name! The Group Name "
123 "was not provided.\n");
124 __COUT_ERR__ << ss.str();
127 else if(groupName.size() == 1)
129 __SS__ << (
"TableGroupKey::getFullGroupString() Illegal Group Name! The Group "
130 "Name is too short: \"" +
133 __COUT_ERR__ << ss.str();
138 for(
unsigned int i = 0; i < groupName.size(); ++i)
141 (groupName[i] >=
'A' && groupName[i] <=
'Z') || (groupName[i] >=
'a' && groupName[i] <=
'z') ||
142 (groupName[i] >=
'0' && groupName[i] <=
'9')))
144 __SS__ << (
"TableGroupKey::getFullGroupString() Illegal Group Name! "
145 "Group Name must be alpha-numeric: \"" +
148 __COUT_ERR__ << ss.str();
154 return groupName +
"_v" + std::to_string(key.key_);
158 void TableGroupKey::getGroupNameAndKey(
const std::string& fullGroupString, std::string& groupName,
TableGroupKey& key)
160 auto i = fullGroupString.rfind(
"_v");
161 groupName = fullGroupString.substr(0, i);