DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
WIB1
AddressTable_search.cpp
Go to the documentation of this file.
1
#include "
wibmod/WIB1/AddressTable.hh
"
2
#include <fstream>
3
#include "
wibmod/WIB1/AddressTableException.hh
"
4
#include <boost/tokenizer.hpp>
//tokenizer
5
#include <stdlib.h>
//strtoul & getenv
6
#include <boost/regex.hpp>
//regex
7
#include <boost/algorithm/string/case_conv.hpp>
//to_upper
8
9
10
std::vector<std::string>
AddressTable::GetNames
(){
11
std::vector<std::string > names;
12
for
(std::map<std::string,Item*>::iterator it =
nameItemMap
.begin();
13
it !=
nameItemMap
.end();
14
it++){
15
names.push_back(it->first);
16
}
17
return
names;
18
}
19
20
void
ReplaceStringInPlace
(std::string& subject,
const
std::string& search,
21
const
std::string& replace) {
22
size_t
pos = 0;
23
while
((pos = subject.find(search, pos)) != std::string::npos) {
24
subject.replace(pos, search.length(), replace);
25
pos += replace.length();
26
}
27
}
28
std::vector<std::string>
AddressTable::GetNames
(std::string
const
®ex){
29
std::vector<std::string > names;
30
//Fix regex
31
std::string rx = regex;
32
std::transform( rx.begin(), rx.end(), rx.begin(), ::toupper);
33
if
( rx.size() > 6 && rx.substr(0,5) ==
"PERL:"
) {
34
printf(
"Using PERL-style regex unchanged\n"
);
35
rx = rx.substr( 5);
36
}
else
{
37
ReplaceStringInPlace
( rx,
"."
,
"#"
);
38
ReplaceStringInPlace
( rx,
"*"
,
".*"
);
39
ReplaceStringInPlace
( rx,
"#"
,
"\\."
);
40
}
41
42
//Create regex match
43
boost::regex re;
44
try
{
45
re = boost::regex(rx);
46
}
catch
(std::exception &e){
47
BUException::BAD_REGEX e2;
48
e2.Append(
"In GetNames: ("
);
49
e2.Append(rx.c_str());
50
e2.Append(
") "
);
51
e2.Append(regex.c_str());
52
throw
e2;
53
}
54
boost::cmatch match;
55
for
(std::map<std::string,Item*>::iterator it =
nameItemMap
.begin();
56
it !=
nameItemMap
.end();
57
it++){
58
if
(regex_match(it->first.c_str(),match,re)){
59
names.push_back(it->first);
60
}
61
}
62
return
names;
63
}
64
65
66
std::vector<std::string>
AddressTable::GetAddresses
(uint16_t lower,uint16_t upper){
67
std::vector<std::string > names;
68
//Get an iterator into our map of addresses to vectors of items that is the first entry that is not less than lower
69
std::map<uint32_t,std::vector<Item*> >::iterator itAddress =
addressItemMap
.lower_bound(lower);
70
for
(;itAddress !=
addressItemMap
.end();itAddress++){
71
//loop over all following address keys
72
73
if
(itAddress->first < upper){
74
//Address key is less than uppper, so add its entries to names
75
std::vector<Item*> & items = itAddress->second;
76
for
(
size_t
iItem = 0; iItem < items.size();iItem++){
77
names.push_back(items[iItem]->name);
78
}
79
}
else
{
80
//address key is greater than or equal to upper, so stop
81
break
;
82
}
83
}
84
return
names;
85
}
86
87
std::vector<std::string>
AddressTable::GetTables
(std::string
const
®ex){
88
89
//Fix regex
90
std::string rx = regex;
91
// std::transform( rx.begin(), rx.end(), rx.begin(), ::toupper);
92
if
( rx.size() > 6 && rx.substr(0,5) ==
"PERL:"
) {
93
printf(
"Using PERL-style regex unchanged\n"
);
94
rx = rx.substr( 5);
95
}
else
{
96
ReplaceStringInPlace
( rx,
"."
,
"#"
);
97
ReplaceStringInPlace
( rx,
"*"
,
".*"
);
98
ReplaceStringInPlace
( rx,
"#"
,
"\\."
);
99
}
100
101
//Create regex match
102
boost::regex re;
103
try
{
104
re = boost::regex(rx);
105
}
catch
(std::exception &e){
106
BUException::BAD_REGEX e2;
107
e2.Append(
"In GetTables: ("
);
108
e2.Append(rx.c_str());
109
e2.Append(
") "
);
110
e2.Append(regex.c_str());
111
throw
e2;
112
}
113
std::set<std::string> tableSearch;
114
boost::cmatch match;
115
for
(std::map<std::string,Item*>::iterator it =
nameItemMap
.begin();
116
it !=
nameItemMap
.end();
117
it++){
118
//Check if this item has a table entry
119
if
(it->second->user.find(
"Table"
) != it->second->user.end()){
120
std::string
const
& tableName = it->second->user.find(
"Table"
)->second;
121
//check if this table isn't already in the set
122
if
(tableSearch.find(tableName) == tableSearch.end()){
123
//Check if we should add it
124
if
(regex_match(tableName.c_str(),match,re)){
125
//Add this table to the set
126
tableSearch.insert(tableName);
127
}
128
}
129
}
130
}
131
std::vector<std::string > tables(tableSearch.begin(),tableSearch.end());
132
return
tables;
133
}
134
135
std::vector<const Item *>
AddressTable::GetTagged
(std::string
const
&tag) {
136
std::vector<const Item *> matches;
137
for
(std::map<std::string,Item*>::iterator it =
nameItemMap
.begin();
138
it !=
nameItemMap
.end();
139
it++){
140
//Check if this item has the tag as an entry
141
if
(it->second->user.find(tag) != it->second->user.end()){
142
matches.push_back(it->second);
143
}
144
}
145
return
matches;
146
}
AddressTableException.hh
AddressTable.hh
ReplaceStringInPlace
void ReplaceStringInPlace(std::string &subject, const std::string &search, const std::string &replace)
Definition
AddressTable_search.cpp:20
AddressTable::addressItemMap
std::map< uint32_t, std::vector< Item * > > addressItemMap
Definition
AddressTable.hh:64
AddressTable::GetAddresses
std::vector< std::string > GetAddresses(uint16_t lower, uint16_t upper)
Definition
AddressTable_search.cpp:66
AddressTable::GetNames
std::vector< std::string > GetNames()
Definition
AddressTable_search.cpp:10
AddressTable::GetTagged
std::vector< Item const * > GetTagged(std::string const &tag)
Definition
AddressTable_search.cpp:135
AddressTable::nameItemMap
std::map< std::string, Item * > nameItemMap
Definition
AddressTable.hh:66
AddressTable::GetTables
std::vector< std::string > GetTables(std::string const ®ex)
Definition
AddressTable_search.cpp:87
Generated on
for DUNE-DAQ by
1.17.0