Skip to content

Commit 26c5d61

Browse files
authored
Handle new CCDB setup by avoiding hardcoding the CCDB url (#15779)
1 parent b122c5f commit 26c5d61

6 files changed

Lines changed: 29 additions & 20 deletions

File tree

Common/SimConfig/src/SimConfig.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
#include "CommonUtils/NameConf.h"
1213
#include <SimConfig/SimConfig.h>
1314
#include <SimConfig/DetectorLists.h>
1415
#include <DetectorsCommonDataFormats/DetID.h>
@@ -69,7 +70,7 @@ void SimConfig::initOptions(boost::program_options::options_description& options
6970
"field", bpo::value<std::string>()->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-<intKGaus>U for uniform field; \"ccdb\" for taking it from CCDB ")("vertexMode", bpo::value<std::string>()->default_value("kDiamondParam"), "Where the beam-spot vertex should come from. Must be one of kNoVertex, kDiamondParam, kCCDB")(
7071
"nworkers,j", bpo::value<int>()->default_value(nsimworkersdefault), "number of parallel simulation workers (only for parallel mode)")(
7172
"noemptyevents", "only writes events with at least one hit")(
72-
"CCDBUrl", bpo::value<std::string>()->default_value("http://alice-ccdb.cern.ch"), "URL for CCDB to be used.")(
73+
"CCDBUrl", bpo::value<std::string>()->default_value(o2::base::NameConf::getCCDBServer()), "URL for CCDB to be used.")(
7374
"timestamp", bpo::value<uint64_t>(), "global timestamp value in ms (for anchoring) - default is now ... or beginning of run if ALICE run number was given")(
7475
"run", bpo::value<int>()->default_value(-1), "ALICE run number")(
7576
"asservice", bpo::value<bool>()->default_value(false), "run in service/server mode")(

Common/Utils/src/NameConf.cxx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "CommonUtils/NameConf.h"
1313
#include <fmt/format.h>
14+
#include <cstdlib>
1415
#include <memory>
1516

1617
O2ParamImpl(o2::base::NameConf);
@@ -111,10 +112,27 @@ std::string NameConf::getTFIDInfoFileName(const std::string_view prefix)
111112
return buildFileName(prefix, "_", "o2", TFIDINFO, ROOT_EXT_STRING, Instance().mDirTFIDINFO);
112113
}
113114

114-
// Default CCDB server
115+
// Default CCDB server.
116+
//
117+
// Precedence: an explicit NameConf.mCCDBServer (configKeyValues) wins; otherwise
118+
// ALICEO2_CCDB_PRODUCTION_HOST, then ALICEO2_CCDB_HOST, then the compiled-in
119+
// production server. The environment lets a build container reach CCDB through
120+
// a broker (CI's security-proxy) without every tool growing its own option --
121+
// the CCDB test suites, GRPTool and testTPCCalDet already read these names.
122+
// Unset, behaviour is unchanged.
115123
std::string NameConf::getCCDBServer()
116124
{
117-
return Instance().mCCDBServer;
125+
static const std::string kCompiledDefault = "http://alice-ccdb.cern.ch/"; // keep equal to mCCDBServer's initializer
126+
const auto& configured = Instance().mCCDBServer;
127+
if (configured != kCompiledDefault) {
128+
return configured;
129+
}
130+
for (const char* var : {"ALICEO2_CCDB_PRODUCTION_HOST", "ALICEO2_CCDB_HOST"}) {
131+
if (const char* host = std::getenv(var); host && *host) {
132+
return host;
133+
}
134+
}
135+
return configured;
118136
}
119137

120138
std::string NameConf::getConfigOutputFileName(const std::string& procName, const std::string& confName, bool json)

DataFormats/Parameters/src/GRPTool.cxx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,6 @@ enum class GRPCommand {
4444
kPRINTMAG
4545
};
4646

47-
// CCDB host, overridable via ALICEO2_CCDB_HOST as the CCDB test suites do.
48-
// Without it this tool always contacts alice-ccdb.cern.ch, which CcdbApi flags
49-
// as needing an alien token -- fatal in CI, where CCDB is reached through a
50-
// local proxy instead.
51-
namespace
52-
{
53-
std::string defaultCCDBHost()
54-
{
55-
const char* host = std::getenv("ALICEO2_CCDB_HOST");
56-
return (host && *host) ? std::string(host) : std::string("http://alice-ccdb.cern.ch");
57-
}
58-
} // namespace
59-
6047
// options struct filled from command line
6148
struct Options {
6249
std::vector<std::string> readout;
@@ -74,8 +61,8 @@ struct Options {
7461
bool print = false; // whether to print outcome of GRP operation
7562
bool lhciffromccdb = false; // whether only to take GRPLHCIF from CCDB
7663
std::string publishto = "";
77-
std::string ccdbhost = defaultCCDBHost();
78-
bool isRun5 = false; // whether or not this is supposed to be a Run5 detector configuration
64+
std::string ccdbhost = o2::base::NameConf::getCCDBServer(); // honours ALICEO2_CCDB_*; see NameConf::getCCDBServer
65+
bool isRun5 = false; // whether or not this is supposed to be a Run5 detector configuration
7966
std::string vertex = "ccdb";
8067
std::string configKeyValues = "";
8168
uint64_t timestamp = 0;

Detectors/Calibration/testMacros/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ o2_add_executable(get-run-parameters
4747
PUBLIC_LINK_LIBRARIES
4848
O2::DataFormatsCTP
4949
O2::CommonDataFormat
50+
O2::CommonUtils
5051
O2::CCDB)

Detectors/Calibration/testMacros/getRunParameters.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <fstream>
1515
#include <cstdio>
1616
#include "CCDB/BasicCCDBManager.h"
17+
#include "CommonUtils/NameConf.h"
1718
#include "CommonDataFormat/InteractionRecord.h"
1819
#include "CCDB/CcdbApi.h"
1920
#include "CCDB/BasicCCDBManager.h"
@@ -130,7 +131,7 @@ int main(int argc, char* argv[])
130131
long duration = 0;
131132
// duration as O2end - O2start:
132133
auto& ccdb_inst = o2::ccdb::BasicCCDBManager::instance();
133-
ccdb_inst.setURL("http://alice-ccdb.cern.ch");
134+
ccdb_inst.setURL(o2::base::NameConf::getCCDBServer());
134135
std::pair<uint64_t, uint64_t> run_times = ccdb_inst.getRunDuration(run);
135136
long run_O2duration = long(run_times.second - run_times.first);
136137
// access SOR and EOR timestamps

Detectors/GRP/workflows/src/create-grp-ecs.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <regex>
1616
#include <TSystem.h>
1717
#include "DataFormatsParameters/GRPECSObject.h"
18+
#include "CommonUtils/NameConf.h"
1819
#include "DataFormatsCTP/Configuration.h"
1920
#include "DetectorsCommonDataFormats/DetID.h"
2021
#include "CCDB/CcdbApi.h"
@@ -276,7 +277,7 @@ int main(int argc, char** argv)
276277
add_option("end-time,e", bpo::value<long>()->default_value(0), "ECS run end time in ms, start-time+3days is used if 0");
277278
add_option("start-time-ctp", bpo::value<long>()->default_value(0), "run start CTP time in ms, same as ECS if not set or 0");
278279
add_option("end-time-ctp", bpo::value<long>()->default_value(0), "run end CTP time in ms, same as ECS if not set or 0");
279-
add_option("ccdb-server", bpo::value<std::string>()->default_value("http://alice-ccdb.cern.ch"), "CCDB server for upload, local file if empty");
280+
add_option("ccdb-server", bpo::value<std::string>()->default_value(o2::base::NameConf::getCCDBServer()), "CCDB server for upload, local file if empty");
280281
add_option("ccdb-server-input", bpo::value<std::string>()->default_value(""), "CCDB server for inputs (if needed, e.g. CTPConfig), dy default ccdb-server is used");
281282
add_option("meta-data,m", bpo::value<std::string>()->default_value("")->implicit_value(""), "metadata as key1=value1;key2=value2;..");
282283
add_option("refresh", bpo::value<std::string>()->default_value("")->implicit_value("async"), R"(refresh server cache after upload: "none" (or ""), "async" (non-blocking) and "sync" (blocking))");

0 commit comments

Comments
 (0)