Skip to content

Commit

Permalink
[alf] Set SwtWord size on server startup
Browse files Browse the repository at this point in the history
  • Loading branch information
kostorr committed May 24, 2022
1 parent 743762b commit 1048215
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 16 deletions.
15 changes: 14 additions & 1 deletion apps/Alf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Alf : public AliceO2::Common::Program
options.add_options()("sequential",
po::bool_switch(&mOptions.sequentialRpcs)->default_value(false),
"Switch to force DIM RPCs to be executed sequentially");
options.add_options()("swt-word-size",
po::value<std::string>(&mOptions.swtWordSize)->default_value("low"),
"Sets the size of SWT word operations (low, medium, high)");
}

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

// Parse the default SWT word size
SwtWord::Size swtWordSize;
try {
swtWordSize = SwtWord::sizeFromString(mOptions.swtWordSize);
} catch (const ParseException& e) {
Logger::get() << e.what() << LogWarningOps << endm;
Logger::get() << "SWT word size defaulting to low" << LogWarningOps << endm;
}

std::string alfId = ip::host_name();
boost::to_upper(alfId);

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

AlfServer alfServer = AlfServer();
AlfServer alfServer = AlfServer(swtWordSize);

std::vector<roc::CardDescriptor> cardsFound = roc::findCards();
for (auto const& card : cardsFound) {
Expand Down Expand Up @@ -143,6 +155,7 @@ class Alf : public AliceO2::Common::Program
std::string dimDnsNode = "";
bool noFirmwareCheck = false;
bool sequentialRpcs = false;
std::string swtWordSize = "low";
} mOptions;
};

Expand Down
4 changes: 3 additions & 1 deletion apps/AlfClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class AlfClient : public AliceO2::Common::Program
std::make_pair("200", "wait"),
std::make_pair("0xdeadbeef", "write"),
std::make_pair("1", "read"),
std::make_pair("0xbadc0ffee", "write"),
std::make_pair("0xabc1234567badc0ffee", "write"),
std::make_pair("0xdeadbeef9badcaffeee", "write"),
std::make_pair("200", "wait"),
std::make_pair("4", "read") });
std::cout << "[SWT_SEQUENCE] output: " << swtOut << std::endl;
}
Expand Down
2 changes: 2 additions & 0 deletions include/Alf/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct ScaMftPsuException : AliceO2::Common::Exception {
};
struct SwtException : AliceO2::Common::Exception {
};
struct ParseException : AliceO2::Common::Exception {
};
struct IcException : AliceO2::Common::Exception {
};
struct PythonException : AliceO2::Common::Exception {
Expand Down
4 changes: 2 additions & 2 deletions include/Alf/Swt.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Swt : public ScBase

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

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

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

/// Reads SWT words
Expand Down Expand Up @@ -115,6 +114,7 @@ class Swt : public ScBase

private:
static constexpr int DEFAULT_SWT_WAIT_TIME_MS = 3;
SwtWord::Size mSwtWordSize = SwtWord::Size::Low;
};

} // namespace alf
Expand Down
2 changes: 2 additions & 0 deletions include/Alf/SwtWord.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class SwtWord
uint16_t getHigh() const;
Size getSize() const;

static SwtWord::Size sizeFromString(std::string swtWord);

private:
uint32_t mLow;
uint32_t mMed;
Expand Down
13 changes: 7 additions & 6 deletions src/AlfServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace o2
namespace alf
{

AlfServer::AlfServer() : mRpcServers()
AlfServer::AlfServer(SwtWord::Size swtWordSize) : mRpcServers(), mSwtWordSize(swtWordSize)
{
}

Expand Down Expand Up @@ -101,8 +101,8 @@ std::string AlfServer::swtBlobWrite(const std::string& parameter, AlfLink link)
{

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

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

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

if (operation == Swt::Operation::Write) {
SwtWord word;
word.setSize(swtWordSize);
std::string hexString = swtPair[0];
std::string leadingHex = "0x";

Expand Down Expand Up @@ -540,13 +541,13 @@ std::vector<std::pair<Sca::Operation, Sca::Data>> AlfServer::parseStringToScaPai
return pairs;
}

std::vector<std::pair<Swt::Operation, Swt::Data>> AlfServer::parseStringToSwtPairs(std::vector<std::string> stringPairs)
std::vector<std::pair<Swt::Operation, Swt::Data>> AlfServer::parseStringToSwtPairs(std::vector<std::string> stringPairs, const SwtWord::Size swtWordSize)
{

std::vector<std::pair<Swt::Operation, Swt::Data>> pairs;
for (const auto& stringPair : stringPairs) {
if (stringPair.find('#') == std::string::npos) {
pairs.push_back(stringToSwtPair(stringPair));
pairs.push_back(stringToSwtPair(stringPair, swtWordSize));
}
}
return pairs;
Expand Down
9 changes: 6 additions & 3 deletions src/AlfServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace alf
class AlfServer
{
public:
AlfServer();
AlfServer(SwtWord::Size swtWordSize = SwtWord::Size::Low);
void makeRpcServers(std::vector<AlfLink> links, bool sequentialRpcs = false);

private:
Expand All @@ -64,11 +64,11 @@ class AlfServer

static std::vector<uint32_t> stringToRegisterPair(const std::string stringPair);
static std::pair<Sca::Operation, Sca::Data> stringToScaPair(const std::string stringPair);
static std::pair<Swt::Operation, Swt::Data> stringToSwtPair(const std::string stringPair);
static std::pair<Swt::Operation, Swt::Data> stringToSwtPair(const std::string stringPair, const SwtWord::Size swtWordSize);
static std::pair<Ic::Operation, Ic::Data> stringToIcPair(const std::string stringPair);
static std::vector<std::vector<uint32_t>> parseStringToRegisterPairs(std::vector<std::string> stringPairs);
static std::vector<std::pair<Sca::Operation, Sca::Data>> parseStringToScaPairs(std::vector<std::string> stringPairs);
static std::vector<std::pair<Swt::Operation, Swt::Data>> parseStringToSwtPairs(std::vector<std::string> stringPairs);
static std::vector<std::pair<Swt::Operation, Swt::Data>> parseStringToSwtPairs(std::vector<std::string> stringPairs, const SwtWord::Size swtWordSize);
static std::vector<std::pair<Ic::Operation, Ic::Data>> parseStringToIcPairs(std::vector<std::string> stringPairs);
static roc::PatternPlayer::Info parseStringToPatternPlayerInfo(const std::vector<std::string> sringsPairs);

Expand All @@ -80,6 +80,9 @@ class AlfServer
/// serialId -> link -> vector of RPC servers
std::map<roc::SerialId, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>, serialIdComparator> mRpcServers;
std::map<roc::SerialId, std::shared_ptr<lla::Session>, serialIdComparator> mSessions;

// default size for SWT read operations
SwtWord::Size mSwtWordSize;
};

} // namespace alf
Expand Down
6 changes: 3 additions & 3 deletions src/Swt.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace alf

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

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

for (const auto& result : results) {
ret.push_back({ Operation::Read, result });
Expand Down
17 changes: 17 additions & 0 deletions src/SwtWord.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#include <cstdint>
#include <cstddef>
#include <iomanip>
#include <string>
#include <boost/algorithm/string.hpp>

#include "Alf/SwtWord.h"
#include "Alf/Exception.h"

namespace o2
{
Expand Down Expand Up @@ -108,6 +111,20 @@ SwtWord::Size SwtWord::getSize() const
return mSize;
}

SwtWord::Size SwtWord::sizeFromString(std::string swtWord)
{
boost::to_lower(swtWord);
if (swtWord == "low") {
return SwtWord::Size::Low;
} else if (swtWord == "med" || swtWord == "medium") {
return SwtWord::Size::Medium;
} else if (swtWord == "high") {
return SwtWord::Size::High;
}

BOOST_THROW_EXCEPTION(ParseException() << ErrorInfo::Message("Cannot parse swt word size from: \"" + swtWord + "\". Can be \"low\", \"med\", \"medium\", or \"high\""));
}

std::ostream& operator<<(std::ostream& output, const SwtWord& swtWord)
{
output << "0x" << std::setfill('0') << std::hex << std::setw(3) << swtWord.getHigh()
Expand Down

0 comments on commit 1048215

Please sign in to comment.