Skip to content

Commit 7853adf

Browse files
committed
Update roc-bar-stress and roc-metrics with --id flag
1 parent a4d10d1 commit 7853adf

File tree

7 files changed

+60
-37
lines changed

7 files changed

+60
-37
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,25 @@ set(EXE_NAMES
195195

196196
if(PDA_FOUND)
197197
list(APPEND EXE_SRCS
198-
#ProgramBarStress.cxx
198+
ProgramBarStress.cxx
199199
ProgramConfig.cxx
200200
ProgramCleanup.cxx
201201
../Example.cxx
202202
ProgramFlash.cxx
203203
ProgramFlashRead.cxx
204204
ProgramListCards.cxx
205-
#ProgramMetrics.cxx
205+
ProgramMetrics.cxx
206206
ProgramStatus.cxx
207207
)
208208
list(APPEND EXE_NAMES
209-
#roc-bar-stress
209+
roc-bar-stress
210210
roc-config
211211
roc-channel-cleanup
212212
roc-example
213213
roc-flash
214214
roc-flash-read
215215
roc-list-cards
216-
#roc-metrics
216+
roc-metrics
217217
roc-status
218218
)
219219

include/ReadoutCard/ParameterTypes/PciAddress.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef ALICEO2_READOUTCARD_INCLUDE_PCIADDRESS_H_
77
#define ALICEO2_READOUTCARD_INCLUDE_PCIADDRESS_H_
88

9+
#include <iostream>
910
#include <string>
1011
#include <boost/optional.hpp>
1112

@@ -40,6 +41,8 @@ class PciAddress
4041
return (bus == other.bus) && (slot == other.slot) && (function == other.function);
4142
}
4243

44+
friend std::ostream& operator<<(std::ostream& os, const PciAddress& pciAddress);
45+
4346
/// Gets the bus number of this address
4447
/// \return Integer from 0 to 255 (0xff)
4548
int getBus() const

include/ReadoutCard/ParameterTypes/PciSequenceNumber.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef ALICEO2_READOUTCARD_INCLUDE_PCISEQUENCENUMBER_H_
77
#define ALICEO2_READOUTCARD_INCLUDE_PCISEQUENCENUMBER_H_
88

9+
#include <iostream>
910
#include <string>
1011
#include <boost/optional.hpp>
1112

@@ -25,18 +26,23 @@ class PciSequenceNumber
2526
/// For example: "#04"
2627
static boost::optional<PciSequenceNumber> fromString(std::string string);
2728

29+
std::string toString() const;
30+
2831
bool operator==(const int& other) const
2932
{
3033
return mSequenceNumber == other;
3134
}
32-
35+
3336
bool operator==(const PciSequenceNumber& other) const
3437
{
3538
return mSequenceNumber == other.mSequenceNumber;
3639
}
37-
40+
41+
friend std::ostream& operator<<(std::ostream& os, const PciSequenceNumber& pciSequenceNumber);
42+
3843
private:
3944
int mSequenceNumber;
45+
std::string mSequenceNumberString;
4046
};
4147

4248
} // namespace roc

src/CommandLineUtilities/ProgramBarStress.cxx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ class ProgramBarStress: public Program
2727
virtual Description getDescription()
2828
{
2929
return {"Bar Stress", "Stress the Bar Accessor",
30-
"roc-bar-stress --pci-address 42:00.0 --gbt-link 0 --cycles 100000 --print-freq 10000 --errorcheck"};
30+
"roc-bar-stress --id 42:00.0 --gbt-link 0 --cycles 100000 --print-freq 10000 --errorcheck"};
3131
}
3232

3333
virtual void addOptions(boost::program_options::options_description& options)
3434
{
3535
options.add_options()
36-
("pci-address",
37-
po::value<std::string>(&mOptions.pciAddress)->default_value("-1"),
38-
"Card's PCI Address")
3936
("gbt-link",
4037
po::value<uint32_t>(&mOptions.gbtLink)->default_value(0),
4138
"GBT link over which the bar writes will be performed. CRU is 0-17")
@@ -48,6 +45,7 @@ class ProgramBarStress: public Program
4845
("errorcheck",
4946
po::bool_switch(&mOptions.errorCheck),
5047
"Perform data validation");
48+
Options::addOptionCardId(options);
5149
}
5250

5351
int stress(Swt *swt, long long cycles, long long printFrequency, bool errorCheck)
@@ -107,7 +105,9 @@ class ProgramBarStress: public Program
107105
virtual void run(const boost::program_options::variables_map& map)
108106
{
109107

110-
getLogger() << "PCI Address: " << mOptions.pciAddress << InfoLogger::endm;
108+
auto cardId = Options::getOptionCardId(map);
109+
110+
getLogger() << "Card ID: " << cardId << InfoLogger::endm;
111111
getLogger() << "GBT Link: " << mOptions.gbtLink << InfoLogger::endm;
112112
getLogger() << "Cycles of SWT write(/read) operations: " << mOptions.cycles << InfoLogger::endm;
113113
getLogger() << "Print frequency: " << mOptions.printFrequency << InfoLogger::endm;
@@ -121,11 +121,10 @@ class ProgramBarStress: public Program
121121
getLogger() << "Logging time every " << barOps << " bar operations, of which:" << InfoLogger::endm;
122122
getLogger() << "barWrites: " << barWrites << " | barReads: " << barReads << InfoLogger::endm;
123123

124-
125124
std::shared_ptr<BarInterface>
126-
bar0 = ChannelFactory().getBar(mOptions.pciAddress, 0);
125+
bar0 = ChannelFactory().getBar(cardId, 0);
127126
std::shared_ptr<BarInterface>
128-
bar2 = ChannelFactory().getBar(mOptions.pciAddress, 2);
127+
bar2 = ChannelFactory().getBar(cardId, 2);
129128

130129
if(isVerbose())
131130
getLogger() << "Resetting card..." << InfoLogger::endm;
@@ -153,7 +152,6 @@ class ProgramBarStress: public Program
153152

154153
struct OptionsStruct
155154
{
156-
std::string pciAddress = "-1";
157155
uint32_t gbtLink = 0;
158156
long long cycles = 100;
159157
long long printFrequency = 10;

src/CommandLineUtilities/ProgramMetrics.cxx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,35 @@ class ProgramMetrics: public Program
2525
{
2626
return {"Metrics", "Return current RoC parameters",
2727
"roc-metrics\n"
28-
"roc-metrics --pci-address 42:00.0\n"};
28+
"roc-metrics --id 42:00.0\n"};
2929
}
3030

3131
virtual void addOptions(boost::program_options::options_description& options)
3232
{
33-
options.add_options()
34-
("pci-address",
35-
po::value<std::string>(&mOptions.pciAddress)->default_value("-1"),
36-
"Card's PCI Address");
33+
Options::addOptionCardId(options);
3734
}
3835

3936
virtual void run(const boost::program_options::variables_map& map)
4037
{
4138

39+
auto cardId = Options::getOptionCardId(map);
40+
4241
std::vector<CardDescriptor> cardsFound;
43-
if (mOptions.pciAddress != "-1")
44-
cardsFound = RocPciDevice::findSystemDevices(mOptions.pciAddress);
45-
else
46-
cardsFound = RocPciDevice::findSystemDevices();
47-
4842

43+
if (auto serial = boost::get<int>(&cardId)) {
44+
if (*serial == -1) {
45+
cardsFound = RocPciDevice::findSystemDevices();
46+
} else {
47+
cardsFound = RocPciDevice::findSystemDevices(*serial);
48+
}
49+
} else if (auto pciAddress = boost::get<PciAddress>(&cardId)) {
50+
cardsFound = RocPciDevice::findSystemDevices(*pciAddress);
51+
} else if (auto pciSequenceNumber = boost::get<PciSequenceNumber>(&cardId)) {
52+
cardsFound = RocPciDevice::findSystemDevices(*pciSequenceNumber);
53+
} else {
54+
std::cout << "Something went wrong parsing the card id" << std::endl;
55+
}
56+
4957
std::ostringstream table;
5058

5159
auto formatHeader = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n";
@@ -82,19 +90,10 @@ class ProgramMetrics: public Program
8290
std::cout << table.str();
8391
}
8492

85-
struct OptionsStruct
86-
{
87-
std::string pciAddress = "-1";
88-
}mOptions;
89-
9093
private:
9194
};
9295

9396
int main(int argc, char** argv)
9497
{
95-
if (argc > 2){
96-
std::cout << "Too many arguments" << std::endl;
97-
return -1;
98-
}
9998
return ProgramMetrics().execute(argc, argv);
10099
}

src/ParameterTypes/PciAddress.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@ boost::optional<PciAddress> PciAddress::fromString(std::string string)
7373
}
7474
}
7575

76+
std::ostream& operator<<(std::ostream& os, const PciAddress& pciAddress)
77+
{
78+
os << pciAddress.toString();
79+
return os;
80+
}
81+
7682
} // namespace roc
7783
} // namespace AliceO2

src/ParameterTypes/PciSequenceNumber.cxx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ namespace roc {
1313
namespace {
1414

1515
int parseSequenceNumberString(const std::string& string) {
16-
std::regex expression ("^#[0-9]+$");
16+
std::regex expression ("^[ \t]*#[0-9]+[ \t]*$");
1717
if (std::regex_search(string, expression)) {
18-
std::string retString = string;
19-
return stoi(retString.erase(0, 1)); //remove initial #
18+
return stoi(string.substr(string.find('#') + 1));
2019
} else {
2120
BOOST_THROW_EXCEPTION(ParseException()
2221
<< ErrorInfo::Message("Parsing PCI sequence number failed"));
@@ -27,9 +26,15 @@ namespace {
2726

2827
PciSequenceNumber::PciSequenceNumber(const std::string& string)
2928
{
29+
mSequenceNumberString = string;
3030
mSequenceNumber = parseSequenceNumberString(string);
3131
}
3232

33+
std::string PciSequenceNumber::toString() const
34+
{
35+
return mSequenceNumberString;
36+
}
37+
3338
boost::optional<PciSequenceNumber> PciSequenceNumber::fromString(std::string string)
3439
{
3540
try {
@@ -40,5 +45,11 @@ boost::optional<PciSequenceNumber> PciSequenceNumber::fromString(std::string str
4045
}
4146
}
4247

48+
std::ostream& operator<<(std::ostream& os, const PciSequenceNumber& pciSequenceNumber)
49+
{
50+
os << pciSequenceNumber.toString();
51+
return os;
52+
}
53+
4354
} // namespace roc
4455
} // namespace AliceO2

0 commit comments

Comments
 (0)