Skip to content

Commit 1048215

Browse files
committed
[alf] Set SwtWord size on server startup
1 parent 743762b commit 1048215

File tree

9 files changed

+56
-16
lines changed

9 files changed

+56
-16
lines changed

apps/Alf.cxx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Alf : public AliceO2::Common::Program
6161
options.add_options()("sequential",
6262
po::bool_switch(&mOptions.sequentialRpcs)->default_value(false),
6363
"Switch to force DIM RPCs to be executed sequentially");
64+
options.add_options()("swt-word-size",
65+
po::value<std::string>(&mOptions.swtWordSize)->default_value("low"),
66+
"Sets the size of SWT word operations (low, medium, high)");
6467
}
6568

6669
virtual void run(const po::variables_map&) override
@@ -81,14 +84,23 @@ class Alf : public AliceO2::Common::Program
8184
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("DIM_DNS_NODE env variable not set, and no relevant argument provided.")); // InfoLogger and errors?
8285
}
8386

87+
// Parse the default SWT word size
88+
SwtWord::Size swtWordSize;
89+
try {
90+
swtWordSize = SwtWord::sizeFromString(mOptions.swtWordSize);
91+
} catch (const ParseException& e) {
92+
Logger::get() << e.what() << LogWarningOps << endm;
93+
Logger::get() << "SWT word size defaulting to low" << LogWarningOps << endm;
94+
}
95+
8496
std::string alfId = ip::host_name();
8597
boost::to_upper(alfId);
8698

8799
Logger::get() << "Starting the DIM Server" << LogInfoDevel << endm;
88100
DimServer::setDnsNode(mOptions.dimDnsNode.c_str(), 2505);
89101
DimServer::start(("ALF_" + alfId).c_str());
90102

91-
AlfServer alfServer = AlfServer();
103+
AlfServer alfServer = AlfServer(swtWordSize);
92104

93105
std::vector<roc::CardDescriptor> cardsFound = roc::findCards();
94106
for (auto const& card : cardsFound) {
@@ -143,6 +155,7 @@ class Alf : public AliceO2::Common::Program
143155
std::string dimDnsNode = "";
144156
bool noFirmwareCheck = false;
145157
bool sequentialRpcs = false;
158+
std::string swtWordSize = "low";
146159
} mOptions;
147160
};
148161

apps/AlfClient.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ class AlfClient : public AliceO2::Common::Program
184184
std::make_pair("200", "wait"),
185185
std::make_pair("0xdeadbeef", "write"),
186186
std::make_pair("1", "read"),
187-
std::make_pair("0xbadc0ffee", "write"),
187+
std::make_pair("0xabc1234567badc0ffee", "write"),
188+
std::make_pair("0xdeadbeef9badcaffeee", "write"),
189+
std::make_pair("200", "wait"),
188190
std::make_pair("4", "read") });
189191
std::cout << "[SWT_SEQUENCE] output: " << swtOut << std::endl;
190192
}

include/Alf/Exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct ScaMftPsuException : AliceO2::Common::Exception {
3535
};
3636
struct SwtException : AliceO2::Common::Exception {
3737
};
38+
struct ParseException : AliceO2::Common::Exception {
39+
};
3840
struct IcException : AliceO2::Common::Exception {
3941
};
4042
struct PythonException : AliceO2::Common::Exception {

include/Alf/Swt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Swt : public ScBase
6767

6868
/// Internal constructor for the ALF server
6969
/// \param link AlfLink holding useful information coming from the AlfServer class
70-
Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession);
70+
Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession, SwtWord::Size = SwtWord::Size::Low);
7171

7272
/// External constructor
7373
/// \param cardId The card ID for which to get the SWT handle.
@@ -81,7 +81,6 @@ class Swt : public ScBase
8181

8282
/// Writes an SWT word
8383
/// \param swtWord The SWT word to write
84-
/// \param wordSize The size of the SWT word to be written
8584
void write(const SwtWord& swtWord);
8685

8786
/// Reads SWT words
@@ -115,6 +114,7 @@ class Swt : public ScBase
115114

116115
private:
117116
static constexpr int DEFAULT_SWT_WAIT_TIME_MS = 3;
117+
SwtWord::Size mSwtWordSize = SwtWord::Size::Low;
118118
};
119119

120120
} // namespace alf

include/Alf/SwtWord.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class SwtWord
5858
uint16_t getHigh() const;
5959
Size getSize() const;
6060

61+
static SwtWord::Size sizeFromString(std::string swtWord);
62+
6163
private:
6264
uint32_t mLow;
6365
uint32_t mMed;

src/AlfServer.cxx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace o2
3333
namespace alf
3434
{
3535

36-
AlfServer::AlfServer() : mRpcServers()
36+
AlfServer::AlfServer(SwtWord::Size swtWordSize) : mRpcServers(), mSwtWordSize(swtWordSize)
3737
{
3838
}
3939

@@ -101,8 +101,8 @@ std::string AlfServer::swtBlobWrite(const std::string& parameter, AlfLink link)
101101
{
102102

103103
std::vector<std::string> stringPairs = Util::split(parameter, argumentSeparator());
104-
std::vector<std::pair<Swt::Operation, Swt::Data>> swtPairs = parseStringToSwtPairs(stringPairs);
105-
Swt swt = Swt(link, mSessions[link.serialId]);
104+
std::vector<std::pair<Swt::Operation, Swt::Data>> swtPairs = parseStringToSwtPairs(stringPairs, mSwtWordSize);
105+
Swt swt = Swt(link, mSessions[link.serialId], mSwtWordSize);
106106

107107
bool lock = false;
108108
// Check if the operation should be locked
@@ -360,7 +360,7 @@ std::pair<Sca::Operation, Sca::Data> AlfServer::stringToScaPair(const std::strin
360360
}
361361

362362
/// Converts a 76-bit hex number string
363-
std::pair<Swt::Operation, Swt::Data> AlfServer::stringToSwtPair(const std::string stringPair)
363+
std::pair<Swt::Operation, Swt::Data> AlfServer::stringToSwtPair(const std::string stringPair, const SwtWord::Size swtWordSize)
364364
{
365365
std::vector<std::string> swtPair = Util::split(stringPair, pairSeparator());
366366
if (swtPair.size() < 1 || swtPair.size() > 2) {
@@ -400,6 +400,7 @@ std::pair<Swt::Operation, Swt::Data> AlfServer::stringToSwtPair(const std::strin
400400

401401
if (operation == Swt::Operation::Write) {
402402
SwtWord word;
403+
word.setSize(swtWordSize);
403404
std::string hexString = swtPair[0];
404405
std::string leadingHex = "0x";
405406

@@ -540,13 +541,13 @@ std::vector<std::pair<Sca::Operation, Sca::Data>> AlfServer::parseStringToScaPai
540541
return pairs;
541542
}
542543

543-
std::vector<std::pair<Swt::Operation, Swt::Data>> AlfServer::parseStringToSwtPairs(std::vector<std::string> stringPairs)
544+
std::vector<std::pair<Swt::Operation, Swt::Data>> AlfServer::parseStringToSwtPairs(std::vector<std::string> stringPairs, const SwtWord::Size swtWordSize)
544545
{
545546

546547
std::vector<std::pair<Swt::Operation, Swt::Data>> pairs;
547548
for (const auto& stringPair : stringPairs) {
548549
if (stringPair.find('#') == std::string::npos) {
549-
pairs.push_back(stringToSwtPair(stringPair));
550+
pairs.push_back(stringToSwtPair(stringPair, swtWordSize));
550551
}
551552
}
552553
return pairs;

src/AlfServer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace alf
4747
class AlfServer
4848
{
4949
public:
50-
AlfServer();
50+
AlfServer(SwtWord::Size swtWordSize = SwtWord::Size::Low);
5151
void makeRpcServers(std::vector<AlfLink> links, bool sequentialRpcs = false);
5252

5353
private:
@@ -64,11 +64,11 @@ class AlfServer
6464

6565
static std::vector<uint32_t> stringToRegisterPair(const std::string stringPair);
6666
static std::pair<Sca::Operation, Sca::Data> stringToScaPair(const std::string stringPair);
67-
static std::pair<Swt::Operation, Swt::Data> stringToSwtPair(const std::string stringPair);
67+
static std::pair<Swt::Operation, Swt::Data> stringToSwtPair(const std::string stringPair, const SwtWord::Size swtWordSize);
6868
static std::pair<Ic::Operation, Ic::Data> stringToIcPair(const std::string stringPair);
6969
static std::vector<std::vector<uint32_t>> parseStringToRegisterPairs(std::vector<std::string> stringPairs);
7070
static std::vector<std::pair<Sca::Operation, Sca::Data>> parseStringToScaPairs(std::vector<std::string> stringPairs);
71-
static std::vector<std::pair<Swt::Operation, Swt::Data>> parseStringToSwtPairs(std::vector<std::string> stringPairs);
71+
static std::vector<std::pair<Swt::Operation, Swt::Data>> parseStringToSwtPairs(std::vector<std::string> stringPairs, const SwtWord::Size swtWordSize);
7272
static std::vector<std::pair<Ic::Operation, Ic::Data>> parseStringToIcPairs(std::vector<std::string> stringPairs);
7373
static roc::PatternPlayer::Info parseStringToPatternPlayerInfo(const std::vector<std::string> sringsPairs);
7474

@@ -80,6 +80,9 @@ class AlfServer
8080
/// serialId -> link -> vector of RPC servers
8181
std::map<roc::SerialId, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>, serialIdComparator> mRpcServers;
8282
std::map<roc::SerialId, std::shared_ptr<lla::Session>, serialIdComparator> mSessions;
83+
84+
// default size for SWT read operations
85+
SwtWord::Size mSwtWordSize;
8386
};
8487

8588
} // namespace alf

src/Swt.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace alf
4444

4545
namespace sc_regs = AliceO2::roc::Cru::ScRegisters;
4646

47-
Swt::Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession)
48-
: ScBase(link, llaSession)
47+
Swt::Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession, SwtWord::Size swtWordSize)
48+
: ScBase(link, llaSession), mSwtWordSize(swtWordSize)
4949
{
5050
if (kDebugLogging) {
5151
Logger::setFacility("ALF/SWT");
@@ -146,7 +146,7 @@ std::vector<std::pair<Swt::Operation, Swt::Data>> Swt::executeSequence(std::vect
146146
data = DEFAULT_SWT_TIMEOUT_MS;
147147
timeOut = boost::get<TimeOut>(data);
148148
}
149-
auto results = read(SwtWord::Size::Low, timeOut);
149+
auto results = read(mSwtWordSize, timeOut);
150150

151151
for (const auto& result : results) {
152152
ret.push_back({ Operation::Read, result });

src/SwtWord.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
#include <cstdint>
2929
#include <cstddef>
3030
#include <iomanip>
31+
#include <string>
32+
#include <boost/algorithm/string.hpp>
3133

3234
#include "Alf/SwtWord.h"
35+
#include "Alf/Exception.h"
3336

3437
namespace o2
3538
{
@@ -108,6 +111,20 @@ SwtWord::Size SwtWord::getSize() const
108111
return mSize;
109112
}
110113

114+
SwtWord::Size SwtWord::sizeFromString(std::string swtWord)
115+
{
116+
boost::to_lower(swtWord);
117+
if (swtWord == "low") {
118+
return SwtWord::Size::Low;
119+
} else if (swtWord == "med" || swtWord == "medium") {
120+
return SwtWord::Size::Medium;
121+
} else if (swtWord == "high") {
122+
return SwtWord::Size::High;
123+
}
124+
125+
BOOST_THROW_EXCEPTION(ParseException() << ErrorInfo::Message("Cannot parse swt word size from: \"" + swtWord + "\". Can be \"low\", \"med\", \"medium\", or \"high\""));
126+
}
127+
111128
std::ostream& operator<<(std::ostream& output, const SwtWord& swtWord)
112129
{
113130
output << "0x" << std::setfill('0') << std::hex << std::setw(3) << swtWord.getHigh()

0 commit comments

Comments
 (0)