diff --git a/Common/SimConfig/src/SimConfig.cxx b/Common/SimConfig/src/SimConfig.cxx index 14f99dd4ea580..d1157c821cbbd 100644 --- a/Common/SimConfig/src/SimConfig.cxx +++ b/Common/SimConfig/src/SimConfig.cxx @@ -9,6 +9,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +#include "CommonUtils/NameConf.h" #include #include #include @@ -69,7 +70,7 @@ void SimConfig::initOptions(boost::program_options::options_description& options "field", bpo::value()->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-U for uniform field; \"ccdb\" for taking it from CCDB ")("vertexMode", bpo::value()->default_value("kDiamondParam"), "Where the beam-spot vertex should come from. Must be one of kNoVertex, kDiamondParam, kCCDB")( "nworkers,j", bpo::value()->default_value(nsimworkersdefault), "number of parallel simulation workers (only for parallel mode)")( "noemptyevents", "only writes events with at least one hit")( - "CCDBUrl", bpo::value()->default_value("http://alice-ccdb.cern.ch"), "URL for CCDB to be used.")( + "CCDBUrl", bpo::value()->default_value(o2::base::NameConf::getCCDBServer()), "URL for CCDB to be used.")( "timestamp", bpo::value(), "global timestamp value in ms (for anchoring) - default is now ... or beginning of run if ALICE run number was given")( "run", bpo::value()->default_value(-1), "ALICE run number")( "asservice", bpo::value()->default_value(false), "run in service/server mode")( diff --git a/Common/Utils/src/NameConf.cxx b/Common/Utils/src/NameConf.cxx index 48cefacaf14c7..5c0b83e54d226 100644 --- a/Common/Utils/src/NameConf.cxx +++ b/Common/Utils/src/NameConf.cxx @@ -11,6 +11,7 @@ #include "CommonUtils/NameConf.h" #include +#include #include O2ParamImpl(o2::base::NameConf); @@ -111,10 +112,27 @@ std::string NameConf::getTFIDInfoFileName(const std::string_view prefix) return buildFileName(prefix, "_", "o2", TFIDINFO, ROOT_EXT_STRING, Instance().mDirTFIDINFO); } -// Default CCDB server +// Default CCDB server. +// +// Precedence: an explicit NameConf.mCCDBServer (configKeyValues) wins; otherwise +// ALICEO2_CCDB_PRODUCTION_HOST, then ALICEO2_CCDB_HOST, then the compiled-in +// production server. The environment lets a build container reach CCDB through +// a broker (CI's security-proxy) without every tool growing its own option -- +// the CCDB test suites, GRPTool and testTPCCalDet already read these names. +// Unset, behaviour is unchanged. std::string NameConf::getCCDBServer() { - return Instance().mCCDBServer; + static const std::string kCompiledDefault = "http://alice-ccdb.cern.ch/"; // keep equal to mCCDBServer's initializer + const auto& configured = Instance().mCCDBServer; + if (configured != kCompiledDefault) { + return configured; + } + for (const char* var : {"ALICEO2_CCDB_PRODUCTION_HOST", "ALICEO2_CCDB_HOST"}) { + if (const char* host = std::getenv(var); host && *host) { + return host; + } + } + return configured; } std::string NameConf::getConfigOutputFileName(const std::string& procName, const std::string& confName, bool json) diff --git a/DataFormats/Parameters/src/GRPTool.cxx b/DataFormats/Parameters/src/GRPTool.cxx index 49d9a68decc58..e2ef5658ceadd 100644 --- a/DataFormats/Parameters/src/GRPTool.cxx +++ b/DataFormats/Parameters/src/GRPTool.cxx @@ -44,19 +44,6 @@ enum class GRPCommand { kPRINTMAG }; -// CCDB host, overridable via ALICEO2_CCDB_HOST as the CCDB test suites do. -// Without it this tool always contacts alice-ccdb.cern.ch, which CcdbApi flags -// as needing an alien token -- fatal in CI, where CCDB is reached through a -// local proxy instead. -namespace -{ -std::string defaultCCDBHost() -{ - const char* host = std::getenv("ALICEO2_CCDB_HOST"); - return (host && *host) ? std::string(host) : std::string("http://alice-ccdb.cern.ch"); -} -} // namespace - // options struct filled from command line struct Options { std::vector readout; @@ -74,8 +61,8 @@ struct Options { bool print = false; // whether to print outcome of GRP operation bool lhciffromccdb = false; // whether only to take GRPLHCIF from CCDB std::string publishto = ""; - std::string ccdbhost = defaultCCDBHost(); - bool isRun5 = false; // whether or not this is supposed to be a Run5 detector configuration + std::string ccdbhost = o2::base::NameConf::getCCDBServer(); // honours ALICEO2_CCDB_*; see NameConf::getCCDBServer + bool isRun5 = false; // whether or not this is supposed to be a Run5 detector configuration std::string vertex = "ccdb"; std::string configKeyValues = ""; uint64_t timestamp = 0; diff --git a/Detectors/Calibration/testMacros/CMakeLists.txt b/Detectors/Calibration/testMacros/CMakeLists.txt index f2fdb6687d4e2..6fe446e9ae325 100644 --- a/Detectors/Calibration/testMacros/CMakeLists.txt +++ b/Detectors/Calibration/testMacros/CMakeLists.txt @@ -47,4 +47,5 @@ o2_add_executable(get-run-parameters PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP O2::CommonDataFormat + O2::CommonUtils O2::CCDB) diff --git a/Detectors/Calibration/testMacros/getRunParameters.cxx b/Detectors/Calibration/testMacros/getRunParameters.cxx index d3f9b0a2ece69..ac5047b7c545c 100644 --- a/Detectors/Calibration/testMacros/getRunParameters.cxx +++ b/Detectors/Calibration/testMacros/getRunParameters.cxx @@ -14,6 +14,7 @@ #include #include #include "CCDB/BasicCCDBManager.h" +#include "CommonUtils/NameConf.h" #include "CommonDataFormat/InteractionRecord.h" #include "CCDB/CcdbApi.h" #include "CCDB/BasicCCDBManager.h" @@ -130,7 +131,7 @@ int main(int argc, char* argv[]) long duration = 0; // duration as O2end - O2start: auto& ccdb_inst = o2::ccdb::BasicCCDBManager::instance(); - ccdb_inst.setURL("http://alice-ccdb.cern.ch"); + ccdb_inst.setURL(o2::base::NameConf::getCCDBServer()); std::pair run_times = ccdb_inst.getRunDuration(run); long run_O2duration = long(run_times.second - run_times.first); // access SOR and EOR timestamps diff --git a/Detectors/GRP/workflows/src/create-grp-ecs.cxx b/Detectors/GRP/workflows/src/create-grp-ecs.cxx index d9a73f0737799..4da4a1c18956e 100644 --- a/Detectors/GRP/workflows/src/create-grp-ecs.cxx +++ b/Detectors/GRP/workflows/src/create-grp-ecs.cxx @@ -15,6 +15,7 @@ #include #include #include "DataFormatsParameters/GRPECSObject.h" +#include "CommonUtils/NameConf.h" #include "DataFormatsCTP/Configuration.h" #include "DetectorsCommonDataFormats/DetID.h" #include "CCDB/CcdbApi.h" @@ -276,7 +277,7 @@ int main(int argc, char** argv) add_option("end-time,e", bpo::value()->default_value(0), "ECS run end time in ms, start-time+3days is used if 0"); add_option("start-time-ctp", bpo::value()->default_value(0), "run start CTP time in ms, same as ECS if not set or 0"); add_option("end-time-ctp", bpo::value()->default_value(0), "run end CTP time in ms, same as ECS if not set or 0"); - add_option("ccdb-server", bpo::value()->default_value("http://alice-ccdb.cern.ch"), "CCDB server for upload, local file if empty"); + add_option("ccdb-server", bpo::value()->default_value(o2::base::NameConf::getCCDBServer()), "CCDB server for upload, local file if empty"); add_option("ccdb-server-input", bpo::value()->default_value(""), "CCDB server for inputs (if needed, e.g. CTPConfig), dy default ccdb-server is used"); add_option("meta-data,m", bpo::value()->default_value("")->implicit_value(""), "metadata as key1=value1;key2=value2;.."); add_option("refresh", bpo::value()->default_value("")->implicit_value("async"), R"(refresh server cache after upload: "none" (or ""), "async" (non-blocking) and "sync" (blocking))");