1 #include "otsdaq-core/TableCore/TableGroupKey.h"
3 #include "otsdaq-core/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] !=
'-' &&
31 groupString[i] !=
'_' && groupString[i] !=
'.')
34 if(i == (
int)strlen(groupString) - 1)
36 key_ = TableGroupKey::DEFAULT;
45 sscanf(&groupString[i],
"%u", &key_);
49 TableGroupKey::TableGroupKey(
const std::string& groupString)
55 TableGroupKey::~TableGroupKey(
void) {}
58 unsigned int TableGroupKey::key(
void)
const {
return key_; }
62 bool TableGroupKey::operator==(
unsigned int key)
const {
return (key_ == key); }
63 bool TableGroupKey::operator==(
const TableGroupKey& key)
const
65 return (key_ == key.key_);
70 std::string TableGroupKey::toString(
void)
const
73 return (isInvalid()) ? std::to_string((
int)key_) : std::to_string(key_);
78 TableGroupKey& TableGroupKey::operator=(
const unsigned int key)
85 bool TableGroupKey::operator!=(
unsigned int key)
const {
return (key_ != key); }
86 bool TableGroupKey::operator!=(
const TableGroupKey& key)
const
88 return (key_ != key.key_);
95 return (key_ < key.key_);
100 bool TableGroupKey::operator>(
const TableGroupKey& key)
const
102 return (key_ > key.key_);
107 bool TableGroupKey::isInvalid()
const {
return (key_ == INVALID); }
122 const unsigned int TableGroupKey::getDefaultKey(
void) {
return DEFAULT; }
125 const unsigned int TableGroupKey::getInvalidKey(
void) {
return INVALID; }
133 std::string TableGroupKey::getFullGroupString(
const std::string& groupName,
136 if(groupName.size() == 0)
139 << (
"TableGroupKey::getFullGroupString() Illegal Group Name! The Group Name "
140 "was not provided.\n");
141 __COUT_ERR__ << ss.str();
144 else if(groupName.size() == 1)
146 __SS__ << (
"TableGroupKey::getFullGroupString() Illegal Group Name! The Group "
147 "Name is too short: \"" +
150 __COUT_ERR__ << ss.str();
155 for(
unsigned int i = 0; i < groupName.size(); ++i)
158 (groupName[i] >=
'A' && groupName[i] <=
'Z') ||
159 (groupName[i] >=
'a' && groupName[i] <=
'z') ||
160 (groupName[i] >=
'0' && groupName[i] <=
'9')))
162 __SS__ << (
"TableGroupKey::getFullGroupString() Illegal Group Name! "
163 "Group Name must be alpha-numeric: \"" +
166 __COUT_ERR__ << ss.str();
172 return groupName +
"_v" + std::to_string(key.key_);
176 void TableGroupKey::getGroupNameAndKey(
const std::string& fullGroupString,
177 std::string& groupName,
180 auto i = fullGroupString.rfind(
"_v");
181 groupName = fullGroupString.substr(0, i);