Skip to content

Commit 8c2cb9f

Browse files
authored
Use the hostname as ALF_ID (#8)
1 parent 0ed2bb4 commit 8c2cb9f

File tree

5 files changed

+23
-46
lines changed

5 files changed

+23
-46
lines changed

apps/ProgramAlf.cxx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
/// \author Pascal Boeschoten ([email protected])
1515
/// \author Kostas Alexopoulos ([email protected])
1616

17+
#include <boost/algorithm/string/case_conv.hpp>
18+
#include <boost/asio.hpp>
1719
#include <cstdlib>
1820

1921
#include "AlfServer.h"
@@ -24,6 +26,7 @@
2426
#include "ReadoutCard/CardFinder.h"
2527
#include "ReadoutCard/ChannelFactory.h"
2628

29+
namespace ip = boost::asio::ip;
2730
namespace po = boost::program_options;
2831

2932
namespace AliceO2
@@ -49,9 +52,7 @@ class ProgramAlf : public AliceO2::Common::Program
4952
{
5053
options.add_options()("dim-dns-node",
5154
po::value<std::string>(&mOptions.dimDnsNode)->default_value(""),
52-
"The DIM DNS node to set the env var if not already set")("alf-id",
53-
po::value<int>(&mOptions.alfId)->default_value(-1),
54-
"The ALF ID");
55+
"The DIM DNS node to set the env var if not already set");
5556
}
5657

5758
virtual void run(const po::variables_map&) override
@@ -71,22 +72,12 @@ class ProgramAlf : public AliceO2::Common::Program
7172
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("DIM_DNS_NODE env variable not set, and no relevant argument provided.")); // InfoLogger and errors?
7273
}
7374

74-
int alfId;
75-
76-
if (const char* alfIdString = std::getenv("ALF_ID")) {
77-
getLogger() << "Setting ALF_ID from argument." << endm;
78-
alfId = mOptions.alfId;
79-
getLogger() << "ALF_ID=" << alfId << endm;
80-
} else {
81-
getLogger() << "Picked up ALF_ID from the environment." << endm;
82-
getLogger() << "ALF_ID=" << alfIdString << endm;
83-
alfId = atoi(alfIdString);
84-
}
85-
75+
std::string alfId = ip::host_name();
76+
boost::to_upper(alfId);
8677

8778
getLogger() << "Starting the DIM Server" << endm;
8879
DimServer::setDnsNode(mOptions.dimDnsNode.c_str(), 2505);
89-
DimServer::start(alfId == -1 ? "ALF" : ("ALF" + std::to_string(alfId)).c_str());
80+
DimServer::start(("ALF_" + alfId).c_str());
9081

9182
AlfServer alfServer = AlfServer();
9283

@@ -133,7 +124,6 @@ class ProgramAlf : public AliceO2::Common::Program
133124
private:
134125
struct OptionsStruct {
135126
std::string dimDnsNode = "";
136-
int alfId = -1;
137127
} mOptions;
138128
};
139129

apps/ProgramAlfClient.cxx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
/// \author Pascal Boeschoten ([email protected])
1515
/// \author Kostas Alexopoulos ([email protected])
1616

17+
#include <boost/algorithm/string/case_conv.hpp>
18+
#include <boost/asio.hpp>
1719
#include <chrono>
1820
#include <cstdlib>
1921
#include <thread>
@@ -24,6 +26,7 @@
2426
#include "DimServices/ServiceNames.h"
2527
#include "Logger.h"
2628

29+
namespace ip = boost::asio::ip;
2730
namespace po = boost::program_options;
2831

2932
namespace AliceO2
@@ -47,9 +50,6 @@ class ProgramAlfClient : public AliceO2::Common::Program
4750

4851
virtual void addOptions(po::options_description& options) override
4952
{
50-
options.add_options()("alf-id",
51-
po::value<int>(&mOptions.alfId)->default_value(-1),
52-
"The ID of the ALF server.");
5353
options.add_options()("dim-dns-node",
5454
po::value<std::string>(&mOptions.dimDnsNode)->default_value(""),
5555
"The DIM DNS node to connect to if the env var is not set");
@@ -66,32 +66,23 @@ class ProgramAlfClient : public AliceO2::Common::Program
6666

6767
getLogger() << "ALF client initializations..." << endm;
6868

69-
if (const char* alfIdString = std::getenv("ALF_ID")) {
70-
getLogger() << "Picked up ALF_ID from the environment." << endm;
71-
getLogger() << "ALF_ID=" << alfIdString << endm;
72-
mOptions.alfId = atoi(alfIdString);
73-
} else {
74-
getLogger() << "ALF_ID env variable not set. Setting it from argument." << endm;
75-
//setenv("ALF_ID", std::to_string(mOptions.alfId).c_str(), 1);
76-
getLogger() << "ALF_ID=" << mOptions.alfId << endm;
77-
/* Do I need to set the env var for ALF_ID? */
78-
}
79-
80-
if (const char* dimDnsNode = std::getenv("DIM_DNS_NODE")) {
69+
if (mOptions.dimDnsNode != "") {
70+
getLogger() << "DIM_DNS_NODE env variable not set. Setting it from argument." << endm;
71+
getLogger() << "DIM_DNS_NODE=" << mOptions.dimDnsNode << endm;
72+
} else if (const char* dimDnsNode = std::getenv("DIM_DNS_NODE")) {
8173
getLogger() << "Picked up DIM_DMS_NODE from the environment." << endm;
8274
getLogger() << "DIM_DNS_NODE=" << dimDnsNode << endm;
8375
mOptions.dimDnsNode = dimDnsNode;
84-
} else if (mOptions.dimDnsNode != "") {
85-
getLogger() << "DIM_DNS_NODE env variable not set. Setting it from argument." << endm;
86-
setenv("DIM_DNS_NODE", mOptions.dimDnsNode.c_str(), 1); // Don't be afraid to overwrite since we ended up here
87-
getLogger() << "DIM_DNS_NODE=" << mOptions.dimDnsNode << endm;
8876
} else {
8977
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("DIM_DNS_NODE env variable not set, and no relevant argument provided.")); // InfoLogger and errors?
9078
}
9179

92-
getLogger() << "Starting the DIM Client using ALF ID=" << mOptions.alfId << ", serial=" << mOptions.serial << " and link=" << mOptions.link << endm;
80+
std::string alfId = ip::host_name();
81+
boost::to_upper(alfId);
82+
83+
getLogger() << "Starting the DIM Client using ALF ID=" << alfId << ", serial=" << mOptions.serial << " and link=" << mOptions.link << endm;
9384

94-
AlfLink link = AlfLink{ mOptions.alfId, mOptions.serial, mOptions.link, nullptr };
85+
AlfLink link = AlfLink{ alfId, mOptions.serial, mOptions.link, nullptr };
9586

9687
ServiceNames names(link);
9788
Alf::RegisterReadRpc registerReadRpc(names.registerRead());
@@ -143,7 +134,6 @@ class ProgramAlfClient : public AliceO2::Common::Program
143134
std::string dimDnsNode = "";
144135
int serial = -1;
145136
int link = -1;
146-
int alfId = -1;
147137
} mOptions;
148138
};
149139

src/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static constexpr auto BUSY_TIMEOUT = std::chrono::milliseconds(10);
3232
static constexpr auto CHANNEL_BUSY_TIMEOUT = std::chrono::milliseconds(10);
3333

3434
struct AlfLink {
35-
int alfId;
35+
std::string alfId;
3636
int serial;
3737
int linkId;
3838
std::shared_ptr<roc::BarInterface> bar2;

src/DimServices/ServiceNames.cxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@ DEFSERVICENAME(registerWrite, "REGISTER_WRITE")
3333
DEFSERVICENAME(scaSequence, "SCA_SEQUENCE")
3434
DEFSERVICENAME(swtSequence, "SWT_SEQUENCE")
3535
DEFSERVICENAME(icSequence, "IC_SEQUENCE")
36-
DEFSERVICENAME(icGbtI2cWrite, "IC_GBT_I2C_write")
36+
DEFSERVICENAME(icGbtI2cWrite, "IC_GBT_I2C_WRITE")
3737

3838
std::string ServiceNames::format(std::string name) const
3939
{
40-
if (mAlfId != "-1")
41-
return ((boost::format("ALF%1%/SERIAL_%2%/LINK_%3%/%4%") % mAlfId % mSerial % mLink % name)).str();
42-
else
43-
return ((boost::format("ALF/SERIAL_%1%/LINK_%2%/%3%") % mSerial % mLink % name)).str();
40+
return ((boost::format("ALF_%1%/SERIAL_%2%/LINK_%3%/%4%") % mAlfId % mSerial % mLink % name)).str();
4441
}
4542

4643
} // namespace Alf

src/DimServices/ServiceNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ServiceNames
2929
{
3030
public:
3131
ServiceNames(AlfLink link)
32-
: mAlfId(std::to_string(link.alfId).c_str()), mSerial(link.serial), mLink(link.linkId)
32+
: mAlfId(link.alfId), mSerial(link.serial), mLink(link.linkId)
3333
{
3434
}
3535

0 commit comments

Comments
 (0)