Skip to content

Commit 7b5ef9a

Browse files
committed
[pat-player] Add pattern player service
1 parent fcac4ff commit 7b5ef9a

File tree

6 files changed

+148
-0
lines changed

6 files changed

+148
-0
lines changed

apps/AlfClient.cxx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class AlfClient : public AliceO2::Common::Program
7171
options.add_options()("swt",
7272
po::bool_switch(&mOptions.swt)->default_value(false),
7373
"Flag enabling the swt tests");
74+
options.add_options()("pattern-player",
75+
po::bool_switch(&mOptions.patternPlayer)->default_value(false),
76+
"Flag enabling the pattern player tests");
7477
options.add_options()("swt-stress",
7578
po::bool_switch(&mOptions.swtStress)->default_value(false),
7679
"Flag enabling the swt-stress tests");
@@ -113,6 +116,8 @@ class AlfClient : public AliceO2::Common::Program
113116
ServiceNames names(link);
114117
Alf::RegisterReadRpc registerReadRpc(names.registerRead());
115118
Alf::RegisterWriteRpc registerWriteRpc(names.registerWrite());
119+
Alf::PatternPlayerRpc patternPlayerRpc(names.patternPlayer());
120+
116121
Alf::SwtSequenceRpc swtSequence(names.swtSequence());
117122
Alf::ScaSequenceRpc scaSequence(names.scaSequence());
118123
Alf::IcSequenceRpc icSequence(names.icSequence());
@@ -182,6 +187,26 @@ class AlfClient : public AliceO2::Common::Program
182187
icGbtI2cWriteRpc.write(0x3);
183188
}
184189

190+
if (mOptions.patternPlayer) {
191+
getLogger() << "Running the pattern player" << endm;
192+
auto ppOut = patternPlayerRpc.play({
193+
"0x23456789abcdef123456",
194+
"0x5678",
195+
"0x9abc",
196+
"42",
197+
"0",
198+
"53",
199+
//"30", // comment to test case of less parameters than expected
200+
"29",
201+
"#a comment", // tests that a comment is parsed gracfully
202+
"false",
203+
"true",
204+
"false",
205+
//"0xdeadbeef" // Uncomment to test more parameters than expected
206+
});
207+
getLogger() << "Pairs test return: " << ppOut << endm;
208+
}
209+
185210
getLogger() << "See ya!" << endm;
186211
}
187212

@@ -194,6 +219,7 @@ class AlfClient : public AliceO2::Common::Program
194219
bool ic = false;
195220
bool sca = false;
196221
bool swt = false;
222+
bool patternPlayer = false;
197223
bool swtStress = false;
198224
int swtStressCycles = 2;
199225
int swtStressWords = 1000;

src/AlfClient.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,39 @@ class RegisterWriteRpc : DimRpcInfoWrapper
7777
}
7878
};
7979

80+
class PatternPlayerRpc : DimRpcInfoWrapper
81+
{
82+
public:
83+
PatternPlayerRpc(const std::string& serviceName)
84+
: DimRpcInfoWrapper(serviceName)
85+
{
86+
}
87+
std::string play(const std::string& buffer)
88+
{
89+
setString(buffer);
90+
std::string ret;
91+
try {
92+
ret = getString();
93+
} catch (const AlfException& e) {
94+
getErrorLogger() << "PatternPlayerRpc: " << boost::diagnostic_information(e, true) << endm;
95+
return errString;
96+
}
97+
return ret;
98+
}
99+
100+
std::string play(const std::vector<std::string>& info)
101+
{
102+
std::stringstream buffer;
103+
for (size_t i = 0; i < info.size(); ++i) {
104+
buffer << info[i];
105+
if (i + 1 < info.size()) {
106+
buffer << argumentSeparator();
107+
}
108+
}
109+
return play(buffer.str());
110+
}
111+
};
112+
80113
class ScaSequenceRpc : DimRpcInfoWrapper
81114
{
82115
public:

src/AlfServer.cxx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,84 @@ std::string AlfServer::icGbtI2cWrite(const std::string& parameter, AlfLink link)
9999
return "";
100100
}
101101

102+
std::string AlfServer::patternPlayer(const std::string& parameter, std::shared_ptr<roc::BarInterface> bar2)
103+
{
104+
std::vector<std::string> parameters = Util::split(parameter, argumentSeparator());
105+
if (parameters.size() < 11) { // Test that we have enough parameters
106+
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Wrong number of parameters for the Pattern Player RPC call: " + std::to_string(parameters.size())));
107+
}
108+
109+
roc::PatternPlayer::Info info = parseStringToPatternPlayerInfo(parameters);
110+
111+
roc::PatternPlayer pp = roc::PatternPlayer(bar2);
112+
pp.play(info);
113+
return "";
114+
}
115+
116+
roc::PatternPlayer::Info AlfServer::parseStringToPatternPlayerInfo(const std::vector<std::string> parameters)
117+
{
118+
roc::PatternPlayer::Info ppInfo;
119+
120+
int infoField = 0;
121+
for (const auto& parameter : parameters) {
122+
if (parameter.find('#') == std::string::npos) {
123+
infoField++;
124+
}
125+
}
126+
127+
if (infoField != 11) { // Test that we have enough non-comment parameters
128+
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Wrong number of non-comment parameters for the Pattern Player RPC call: " + std::to_string(infoField)));
129+
}
130+
131+
infoField = 0;
132+
for (const auto& parameter : parameters) {
133+
if (parameter.find('#') == std::string::npos) {
134+
switch (infoField) {
135+
bool boolValue;
136+
case 0:
137+
ppInfo.syncPattern = uint128_t(parameter);
138+
break;
139+
case 1:
140+
ppInfo.resetPattern = uint128_t(parameter);
141+
break;
142+
case 2:
143+
ppInfo.idlePattern = uint128_t(parameter);
144+
break;
145+
case 3:
146+
ppInfo.syncLength = std::stoi(parameter);
147+
break;
148+
case 4:
149+
ppInfo.syncDelay = std::stoi(parameter);
150+
break;
151+
case 5:
152+
ppInfo.resetLength = std::stoi(parameter);
153+
break;
154+
case 6:
155+
ppInfo.resetTriggerSelect = std::stoi(parameter);
156+
break;
157+
case 7:
158+
ppInfo.syncTriggerSelect = std::stoi(parameter);
159+
break;
160+
case 8:
161+
std::istringstream(parameter) >> std::boolalpha >> boolValue;
162+
ppInfo.syncAtStart = boolValue;
163+
break;
164+
case 9:
165+
std::istringstream(parameter) >> std::boolalpha >> boolValue;
166+
ppInfo.triggerSync = boolValue;
167+
break;
168+
case 10:
169+
std::istringstream(parameter) >> std::boolalpha >> boolValue;
170+
ppInfo.triggerReset = boolValue;
171+
break;
172+
}
173+
infoField++;
174+
}
175+
}
176+
177+
return ppInfo;
178+
}
179+
102180
Sca::CommandData AlfServer::stringToScaPair(std::string stringPair)
103181
{
104182
std::vector<std::string> scaPair = Util::split(stringPair, pairSeparator());
@@ -309,6 +387,10 @@ void AlfServer::makeRpcServers(std::vector<AlfLink> links)
309387
// Register Write
310388
servers.push_back(makeServer(names.registerWrite(),
311389
[bar2](auto parameter) { return registerWrite(parameter, bar2); }));
390+
391+
// Register Write
392+
servers.push_back(makeServer(names.patternPlayer(),
393+
[bar2](auto parameter) { return patternPlayer(parameter, bar2); }));
312394
}
313395

314396
// SCA Sequence

src/AlfServer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "Common.h"
2828
#include "Ic/Ic.h"
2929

30+
#include "ReadoutCard/PatternPlayer.h"
31+
3032
namespace roc = AliceO2::roc;
3133

3234
namespace AliceO2
@@ -47,13 +49,15 @@ class AlfServer
4749
static std::string swtBlobWrite(const std::string& parameter, AlfLink link);
4850
static std::string icBlobWrite(const std::string& parameter, AlfLink link);
4951
static std::string icGbtI2cWrite(const std::string& parameter, AlfLink link);
52+
static std::string patternPlayer(const std::string& parameter, std::shared_ptr<roc::BarInterface>);
5053

5154
static Sca::CommandData stringToScaPair(std::string stringPair);
5255
static std::pair<Swt::SwtData, Swt::Operation> stringToSwtPair(const std::string stringPair);
5356
static std::pair<Ic::IcData, Ic::Operation> stringToIcPair(const std::string stringPair);
5457
static std::vector<Sca::CommandData> parseStringToScaCommands(std::vector<std::string> stringPairs);
5558
static std::vector<std::pair<Swt::SwtData, Swt::Operation>> parseStringToSwtPairs(std::vector<std::string> stringPairs);
5659
static std::vector<std::pair<Ic::IcData, Ic::Operation>> parseStringToIcPairs(std::vector<std::string> stringPairs);
60+
static roc::PatternPlayer::Info parseStringToPatternPlayerInfo(const std::vector<std::string> sringsPairs);
5761

5862
/// cruSequence -> link -> vector of RPC servers
5963
std::map<int, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>> mRpcServers;

src/DimServices/ServiceNames.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace Alf
3636

3737
DEFCARDSERVICENAME(registerRead, "REGISTER_READ")
3838
DEFCARDSERVICENAME(registerWrite, "REGISTER_WRITE")
39+
DEFCARDSERVICENAME(patternPlayer, "PATTERN_PLAYER")
40+
3941
DEFLINKSERVICENAME(scaSequence, "SCA_SEQUENCE")
4042
DEFLINKSERVICENAME(swtSequence, "SWT_SEQUENCE")
4143
DEFLINKSERVICENAME(icSequence, "IC_SEQUENCE")

src/DimServices/ServiceNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ServiceNames
3939
std::string swtSequence() const;
4040
std::string icSequence() const;
4141
std::string icGbtI2cWrite() const;
42+
std::string patternPlayer() const;
4243

4344
private:
4445
std::string formatLink(std::string name) const;

0 commit comments

Comments
 (0)