Skip to content

Commit f88391b

Browse files
committed
[python] Introduce python bindings
1 parent 978efb6 commit f88391b

File tree

17 files changed

+1383
-13
lines changed

17 files changed

+1383
-13
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ find_package(ReadoutCard REQUIRED)
5858
find_package(LLA REQUIRED)
5959
find_package(DIM REQUIRED)
6060

61+
if(NOT APPLE)
62+
find_package(Python3 3.6 COMPONENTS Interpreter Development)
63+
if(Python3_FOUND)
64+
set(boost_python_component "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
65+
else()
66+
# Backwards compatible. Can be removed once the Python3 recipe is stable
67+
message(WARNING "Python 3 was not found: falling back to Python 2")
68+
find_package(Python2 2.7 COMPONENTS Development REQUIRED)
69+
set(boost_python_component "python27")
70+
endif()
71+
endif()
72+
6173
####################################
6274
# Module, library and executable definition
6375
####################################
@@ -75,6 +87,8 @@ target_sources(ALF PRIVATE
7587
src/DimServices/DimServices.cxx
7688
src/DimServices/ServiceNames.cxx
7789
src/Logger.cxx
90+
$<$<BOOL:${Python2_FOUND}>:src/PythonInterface.cxx>
91+
$<$<BOOL:${Python3_FOUND}>:src/PythonInterface.cxx>
7892
)
7993

8094
target_include_directories(ALF
@@ -91,6 +105,10 @@ set(LINK_LIBS
91105
AliceO2::Common
92106
AliceO2::InfoLogger
93107
Boost::boost
108+
$<$<BOOL:${Python2_FOUND}>:Boost::python27>
109+
$<$<BOOL:${Python2_FOUND}>:Python2::Python>
110+
$<$<BOOL:${Python3_FOUND}>:Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}>
111+
$<$<BOOL:${Python3_FOUND}>:Python3::Python>
94112
)
95113

96114
# Link targets

include/Alf/Exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct SwtException : AliceO2::Common::Exception {
3131
};
3232
struct IcException : AliceO2::Common::Exception {
3333
};
34+
struct PythonException : AliceO2::Common::Exception {
35+
};
3436

3537
namespace ErrorInfo
3638
{

include/Alf/Ic.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ class Ic
7474
/// \param gbtChannel The IC channel to set.
7575
void setChannel(int gbtChannel);
7676

77-
/// Checks if an IC channel is selected
78-
/// \throws o2::alf::IcException if no IC channel selected
79-
void checkChannelSet();
80-
8177
/// Executes an SC reset
8278
void scReset();
8379

@@ -133,8 +129,16 @@ class Ic
133129
/// o2::lla::LlaException on lock fail
134130
std::string writeSequence(std::vector<std::pair<Operation, Data>> ops, bool lock = false);
135131

132+
static std::string IcOperationToString(Operation op);
133+
static Ic::Operation StringToIcOperation(std::string op);
134+
136135
private:
137136
void init(const roc::Parameters::CardIdType& cardId, int linkId);
137+
138+
/// Checks if an IC channel is selected
139+
/// \throws o2::alf::IcException if no IC channel selected
140+
void checkChannelSet();
141+
138142
void barWrite(uint32_t offset, uint32_t data);
139143
uint32_t barRead(uint32_t index);
140144

include/Alf/Sca.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ class Sca
7676
/// \param gbtChannel The channel to set
7777
void setChannel(int gbtChannel);
7878

79-
/// Checks if an SCA channel has been selected
80-
/// \throws o2::alf::ScaException if no SCA channel selected
81-
void checkChannelSet();
82-
8379
/// Executes a global SC reset
8480
void scReset();
8581

@@ -124,9 +120,16 @@ class Sca
124120
/// o2::alf::ScaException on invalid operation or error
125121
std::string writeSequence(const std::vector<std::pair<Operation, Data>>& operations, bool lock = false);
126122

123+
static std::string ScaOperationToString(Operation op);
124+
static Sca::Operation StringToScaOperation(std::string op);
125+
127126
private:
128127
void init(const roc::Parameters::CardIdType& cardId, int linkId);
129128

129+
/// Checks if an SCA channel has been selected
130+
/// \throws o2::alf::ScaException if no SCA channel selected
131+
void checkChannelSet();
132+
130133
uint32_t barRead(uint32_t index);
131134
void barWrite(uint32_t index, uint32_t data);
132135

include/Alf/Swt.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ class Swt
8080
/// \param gbtChannel The channel to set
8181
void setChannel(int gbtChannel);
8282

83-
/// Checks if an SWT channel has been selected
84-
/// \throws o2::alf::SwtException if no SWT channel selected
85-
void checkChannelSet();
86-
8783
/// Executes an SC reset
8884
void scReset();
8985

@@ -116,8 +112,18 @@ class Swt
116112
/// o2::alf::SwtException on invalid operation or error
117113
std::string writeSequence(std::vector<std::pair<Operation, Data>> sequence, bool lock = false);
118114

115+
static std::string SwtOperationToString(Operation op);
116+
static Operation StringToSwtOperation(std::string op);
117+
118+
static constexpr int DEFAULT_SWT_TIMEOUT_MS = 10;
119+
119120
private:
120121
void init(const roc::Parameters::CardIdType& cardId, int linkId);
122+
123+
/// Checks if an SWT channel has been selected
124+
/// \throws o2::alf::SwtException if no SWT channel selected
125+
void checkChannelSet();
126+
121127
void barWrite(uint32_t offset, uint32_t data);
122128
uint32_t barRead(uint32_t index);
123129

@@ -127,7 +133,6 @@ class Swt
127133
std::unique_ptr<LlaSession> mLlaSession;
128134

129135
static constexpr int DEFAULT_SWT_WAIT_TIME_MS = 3;
130-
static constexpr int DEFAULT_SWT_TIMEOUT_MS = 10;
131136
};
132137

133138
} // namespace alf

include/Alf/SwtWord.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SwtWord
5050
void setMed(uint32_t med);
5151
void setHigh(uint16_t high);
5252
void setSize(Size size);
53+
void setSize(std::string size);
5354
uint32_t getLow() const;
5455
uint32_t getMed() const;
5556
uint16_t getHigh() const;

src/Ic.cxx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,33 @@ std::string Ic::writeSequence(std::vector<std::pair<Operation, Data>> ops, bool
277277
return resultBuffer.str();
278278
}
279279

280+
std::string Ic::IcOperationToString(Ic::Operation op) {
281+
if (op == Ic::Operation::Read) {
282+
return "read";
283+
} else if (op == Ic::Operation::Write) {
284+
return "write";
285+
} else if (op == Ic::Operation::Error) {
286+
return "error";
287+
} else if (op == Ic::Operation::Lock) {
288+
return "lock";
289+
}
290+
291+
BOOST_THROW_EXCEPTION(IcException() << ErrorInfo::Message("Cannot convert Ic operation to string"));
292+
}
293+
294+
Ic::Operation Ic::StringToIcOperation(std::string op) {
295+
if (op == "read") {
296+
return Ic::Operation::Read;
297+
} else if (op == "write") {
298+
return Ic::Operation::Write;
299+
} else if (op == "error") {
300+
return Ic::Operation::Error;
301+
} else if (op == "lock") {
302+
return Ic::Operation::Lock;
303+
}
304+
305+
BOOST_THROW_EXCEPTION(IcException() << ErrorInfo::Message("Cannot convert IC operation to string " + op));
306+
}
307+
280308
} // namespace alf
281309
} // namespace o2

0 commit comments

Comments
 (0)