DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
WIB1
AddressTable_item.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
static
const
char
*
SC_key_conv
=
"sc_conv"
;
10
11
Item
const
*
AddressTable::GetItem
(std::string
const
& registerName){
12
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(registerName);
13
if
(itNameItem ==
nameItemMap
.end()){
14
BUException::INVALID_NAME e;
15
e.Append(
"Can't find item with name \""
);
16
e.Append(registerName.c_str());
17
e.Append(
"\""
);
18
throw
e;
19
}
20
Item
* item = itNameItem->second;
21
return
item;
22
}
23
24
void
AddressTable::AddEntry
(
Item
* item){
25
//Check for null item
26
if
(item == NULL){
27
BUException::NULL_POINTER e;
28
e.Append(
"Null Item pointer passed to AddEntry\n"
);
29
throw
e;
30
}
31
//Check for invalid Mode
32
if
((item->
mode
&
Item::WRITE
) &&
33
(item->
mode
&
Item::ACTION
)){
34
BUException::BAD_MODE e;
35
e.Append(
"AddEntry called with both WRITE and ACTION modes\n"
);
36
throw
e;
37
}
38
39
//This function now owns the memory at item
40
41
42
43
//Add the item to the address map and check that it doesn't conflict with
44
std::map<uint32_t,std::vector<Item*> >::iterator itAddressItem =
addressItemMap
.find(item->
address
);
45
if
(itAddressItem ==
addressItemMap
.end()){
46
//This is the first entry at this address.
47
//Create the entry in addressItemMap and then push_back with our item.
48
addressItemMap
[item->
address
].push_back(item);
49
//Update the iterator to the newly inserted item
50
itAddressItem =
addressItemMap
.find(item->
address
);
51
}
else
{
52
std::vector<Item*> & addressItems = itAddressItem->second;
53
//Check each entry for an overlap in masks. This is only ok if one is a subset, via it's name, of the other
54
for
(
size_t
iItem = 0; iItem < addressItems.size();iItem++){
55
if
(addressItems[iItem]->mask & item->
mask
){
56
//free for all now
57
58
59
//These items overlap in mask
60
//CHeck that one or the other contains the other starting at pos 0.
61
//in other words, that they are the same up until the end of the shorter one
62
// if( (addressItems[iItem]->name.find(item->name) != 0) &&
63
// (item->name.find(addressItems[iItem]->name) != 0) ) {
64
// BUException::BAD_MODE e;
65
// e.Append("Entry: ");
66
// e.Append(item->name.c_str());
67
// e.Append(" conflicts with entry ");
68
// e.Append(addressItems[iItem]->name.c_str());
69
// e.Append("\n");
70
// throw e;
71
// }
72
}
73
}
74
addressItems.push_back(item);
75
}
76
77
//Add the item to the list of addresses
78
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(item->
name
);
79
if
(itNameItem ==
nameItemMap
.end()){
80
//Add this entry and everything is good.
81
nameItemMap
[item->
name
] = item;
82
}
else
{
83
//There was a collision in entry name, remote the newly added element and throw an exception
84
85
//delete the addition to the vector
86
std::vector<Item*> & addressItems = itAddressItem->second;
87
for
(
size_t
iItem = 0; iItem < addressItems.size();iItem++){
88
if
(addressItems[iItem] == item){
89
//Found what we just added, removing
90
addressItems.erase(addressItems.begin()+iItem);
91
}
92
}
93
// throw exception about collission
94
BUException::NAME_COLLISION e;
95
e.Append(
"Item "
);
96
e.Append(item->
name
.c_str());
97
e.Append(
" already existed\n"
);
98
99
//delete the item
100
delete
item;
101
102
throw
e;
103
}
104
105
// Create Slow Control ItemConversion for this item
106
107
item->
sc_conv
= (
ItemConversion
*)0x0;
108
109
if
(item->
user
.count(
SC_key_conv
)) {
110
std::string convstring = item->
user
.at(
SC_key_conv
);
111
item->
sc_conv
=
ItemConversion::FromString
(convstring);
112
if
(!item->
sc_conv
) {
113
fprintf(stderr,
"Warning: Unknown item conversion \"%s\"\n"
,
114
convstring.c_str());
115
item->
sc_conv
=
ItemConversion::FromString
(
"pass"
);
116
}
117
}
else
{
118
item->
sc_conv
=
ItemConversion::FromString
(
"pass"
);
119
}
120
121
//Everything is good, we've added it
122
}
123
124
AddressTableException.hh
AddressTable.hh
SC_key_conv
static const char * SC_key_conv
Definition
AddressTable_item.cpp:9
AddressTable::addressItemMap
std::map< uint32_t, std::vector< Item * > > addressItemMap
Definition
AddressTable.hh:64
AddressTable::AddEntry
void AddEntry(Item *)
Definition
AddressTable_item.cpp:24
AddressTable::GetItem
Item const * GetItem(std::string const &)
Definition
AddressTable_item.cpp:11
AddressTable::nameItemMap
std::map< std::string, Item * > nameItemMap
Definition
AddressTable.hh:66
ItemConversion
Definition
ItemConversion.hh:7
ItemConversion::FromString
static ItemConversion * FromString(std::string convstring)
Definition
conversions.cpp:37
Item
Definition
AddressTable.hh:14
Item::name
std::string name
Definition
AddressTable.hh:17
Item::user
boost::unordered_map< std::string, std::string > user
Definition
AddressTable.hh:22
Item::address
uint16_t address
Definition
AddressTable.hh:18
Item::mask
uint32_t mask
Definition
AddressTable.hh:19
Item::sc_conv
ItemConversion * sc_conv
Definition
AddressTable.hh:23
Item::mode
uint8_t mode
Definition
AddressTable.hh:21
Item::WRITE
@ WRITE
Definition
AddressTable.hh:16
Item::ACTION
@ ACTION
Definition
AddressTable.hh:16
Generated on
for DUNE-DAQ by
1.17.0