17 #include <boost/algorithm/string.hpp> 32 inline std::string _toParenString(tinyxml2::XMLElement
const &nodeToConvert) {
33 std::ostringstream oss;
35 for (
auto child = nodeToConvert.FirstChildElement();
child !=
nullptr;
child =
child->NextSiblingElement()) {
36 for (
auto attribute =
child->FirstAttribute(); attribute !=
nullptr; attribute = attribute->Next()) {
37 oss <<
"(" <<
child->Name() << attribute->Name() <<
"=" << attribute->Value() <<
")";
44 static void overrideFromPSet(
char const *iName,
edm::ParameterSet const &iPSet,
T &iHolder,
T const *&iPointer) {
52 const char *safe(
const char *iCheck) {
53 if (iCheck ==
nullptr) {
61 const char *
tmp = std::getenv(
"SITECONFIG_PATH");
65 returnValue +=
"/JobConfig/site-local-config.xml";
77 : m_url(
pset.getUntrackedParameter<
std::
string>(
"siteLocalConfigFileUrl", defaultURL())),
78 m_trivialDataCatalogs(),
84 m_cacheTempDirPtr(nullptr),
86 m_cacheMinFreePtr(nullptr),
88 m_cacheHintPtr(nullptr),
90 m_cloneCacheHintPtr(nullptr),
92 m_readHintPtr(nullptr),
94 m_ttreeCacheSizePtr(nullptr),
96 m_timeoutPtr(nullptr),
98 m_enablePrefetching(
false),
99 m_enablePrefetchingPtr(nullptr),
101 m_nativeProtocolsPtr(nullptr),
102 m_statisticsDestination(),
103 m_statisticsAddrInfo(nullptr),
104 m_statisticsInfoAvail(
false),
122 std::vector<std::string> tmpStatisticsInfo;
123 std::vector<std::string>
const *tmpStatisticsInfoPtr =
nullptr;
124 overrideFromPSet(
"overrideStatisticsInfo",
pset, tmpStatisticsInfo, tmpStatisticsInfoPtr);
125 if (tmpStatisticsInfoPtr) {
128 for (
auto &
entry : tmpStatisticsInfo) {
133 if (
pset.exists(
"debugLevel")) {
136 if (
pset.exists(
"overrideUseLocalConnectString")) {
139 if (
pset.exists(
"overrideLocalConnectPrefix")) {
142 if (
pset.exists(
"overrideLocalConnectSuffix")) {
156 static std::vector<std::string>
const tmp{
"file:PoolFileCatalog.xml"};
162 ex <<
"Did not find catalogs in event-data section in " <<
m_url;
163 ex.
addContext(
"edm::SiteLocalConfigService::trivialDataCatalogs()");
173 ex <<
"Incomplete configuration. Valid site-local-config not found at " <<
m_url;
174 ex.
addContext(
"edm::SiteLocalConfigService::dataCatalogs()");
179 ex <<
"Did not find catalogs in data-access section in " <<
m_url;
180 ex.
addContext(
"edm::SiteLocalConfigService::dataCatalogs()");
193 if (aDataCatalog.
subSite.empty())
194 filename_storage = siteconfig_path;
197 filename_storage = siteconfig_path +
"/..";
200 if (aDataCatalog.
subSite.empty())
201 filename_storage = siteconfig_path +
"/../" + aDataCatalog.
storageSite;
204 filename_storage = siteconfig_path +
"/../../" + aDataCatalog.
storageSite;
206 filename_storage /=
"storage.json";
208 filename_storage = std::filesystem::canonical(filename_storage);
211 ex <<
"Fail to convert path to the storage description, " << filename_storage.string()
212 <<
", to the canonical absolute path" 214 ex.
addContext(
"edm::SiteLocalConfigService::storageDescriptionPath()");
217 return filename_storage;
222 throw cms::Exception(
"Incomplete configuration") <<
"Valid site-local-config not found at " <<
m_url;
227 <<
"Did not find frontier-connect in calib-data section in " <<
m_url;
230 if (servlet.empty()) {
239 while ((serverurl =
m_frontierConnect.find(
"(serverurl=", nextparen)) != std::string::npos) {
244 complexstr.append(servlet);
254 if (
input.substr(0, proto.length()) == proto) {
272 if (endservlet == std::string::npos) {
273 endservlet =
input.rfind(
'/',
input.length());
275 std::string servlet =
input.substr(startservlet, endservlet - startservlet);
276 if ((!servlet.empty()) && (servlet.find_first_of(
":/)[]") == std::string::npos)) {
277 if (servlet ==
"cms_conditions_data") {
327 aCatalog.
site = site;
331 if (tmp_site.empty())
342 tinyxml2::XMLDocument
doc;
343 auto loadErr =
doc.LoadFile(
url.c_str());
344 if (loadErr != tinyxml2::XML_SUCCESS) {
378 auto rootElement =
doc.RootElement();
380 for (
auto site = rootElement->FirstChildElement(
"site"); site !=
nullptr;
381 site = site->NextSiblingElement(
"site")) {
382 auto subSite = site->FirstChildElement(
"subsite");
389 auto subSite_first_child = subSite->FirstChild();
390 if (subSite_first_child) {
392 ex <<
"Invalid site-local-config.xml. Subsite node has children!";
393 ex.
addContext(
"edm::SiteLocalConfigService::parse()");
400 auto eventData = site->FirstChildElement(
"event-data");
402 auto catalog = eventData->FirstChildElement(
"catalog");
411 auto rfiotype = eventData->FirstChildElement(
"rfiotype");
413 m_rfioType = safe(rfiotype->Attribute(
"value"));
426 auto dataAccess = site->FirstChildElement(
"data-access");
429 auto catalog = dataAccess->FirstChildElement(
"catalog");
445 auto calibData = site->FirstChildElement(
"calib-data");
448 auto frontierConnect = calibData->FirstChildElement(
"frontier-connect");
453 auto localConnect = calibData->FirstChildElement(
"local-connect");
457 <<
"It is illegal to include both frontier-connect and local-connect in the same XML file";
460 auto connectString = localConnect->FirstChildElement(
"connectString");
469 auto sourceConfig = site->FirstChildElement(
"source-config");
472 auto cacheTempDir = sourceConfig->FirstChildElement(
"cache-temp-dir");
479 auto cacheMinFree = sourceConfig->FirstChildElement(
"cache-min-free");
487 auto cacheHint = sourceConfig->FirstChildElement(
"cache-hint");
494 auto cloneCacheHint = sourceConfig->FirstChildElement(
"clone-cache-hint");
496 if (cloneCacheHint) {
501 auto readHint = sourceConfig->FirstChildElement(
"read-hint");
504 m_readHint = safe(readHint->Attribute(
"value"));
508 auto ttreeCacheSize = sourceConfig->FirstChildElement(
"ttree-cache-size");
510 if (ttreeCacheSize) {
515 auto timeout = sourceConfig->FirstChildElement(
"timeout-in-seconds");
522 auto statsDest = sourceConfig->FirstChildElement(
"statistics-destination");
529 std::string tmpStatisticsInfo = safe(statsDest->Attribute(
"info"));
534 auto prefetching = sourceConfig->FirstChildElement(
"prefetching");
541 auto nativeProtocol = sourceConfig->FirstChildElement(
"native-protocols");
543 if (nativeProtocol) {
544 for (
auto child = nativeProtocol->FirstChildElement();
child !=
nullptr;
556 std::vector<std::string> inputStrings;
560 struct addrinfo *
res;
561 struct addrinfo hints;
562 memset(&hints,
'\0',
sizeof(hints));
563 hints.ai_socktype = SOCK_DGRAM;
564 hints.ai_flags = AI_ADDRCONFIG;
565 hints.ai_family = AF_UNSPEC;
566 int e = getaddrinfo(
host.c_str(),
port.c_str(), &hints, &
res);
576 desc.setComment(
"Service to translate logical file names to physical file names.");
580 "Specify the file containing the site local config. Empty string will load from default directory.");
582 desc.addOptionalUntracked<
double>(
"overrideSourceCacheMinFree");
584 desc.addOptionalUntracked<
std::string>(
"overrideSourceCloneCacheHintDir")
585 ->setComment(
"Provide an alternate cache hint for fast cloning.");
587 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideSourceNativeProtocols");
588 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTTreeCacheSize");
589 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTimeout");
590 desc.addOptionalUntracked<
unsigned int>(
"debugLevel");
591 desc.addOptionalUntracked<
bool>(
"overridePrefetching")
592 ->setComment(
"Request ROOT to asynchronously prefetch I/O during computation.");
593 desc.addOptionalUntracked<
std::string>(
"overrideStatisticsDestination")
595 "Provide an alternate network destination for I/O statistics (must be in the form of host:port).");
596 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideStatisticsInfo")
598 "Provide an alternate listing of statistics to send (comma separated list; current options are 'dn' or " 599 "'nodn'). If left blank, all information is snet (including DNs).");
600 desc.addOptionalUntracked<
bool>(
"overrideUseLocalConnectString");
603 descriptions.
add(
"SiteLocalConfigService",
desc);
unsigned int const * m_timeoutPtr
~SiteLocalConfigService() override
std::string const * m_cacheTempDirPtr
std::string m_frontierConnect
void parse(std::string const &url)
std::string m_subSiteName
static void fillDescriptions(ConfigurationDescriptions &descriptions)
struct addrinfo const * statisticsDestination() const override
double const * m_cacheMinFreePtr
std::string const * m_cloneCacheHintPtr
std::vector< edm::CatalogAttributes > m_dataCatalogs
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static const std::string m_statisticsDefaultPort
std::vector< std::string > const & trivialDataCatalogs() const override
std::string const * sourceCacheHint() const override
std::string const * sourceReadHint() const override
std::string m_cloneCacheHint
unsigned int const * sourceTimeout() const override
std::string m_cacheTempDir
void getCatalog(tinyxml2::XMLElement const &cat, std::string site, std::string subSite)
std::string const & subSiteName() const override
unsigned int m_ttreeCacheSize
std::vector< std::string > const * sourceNativeProtocols() const override
std::vector< std::string > const * m_nativeProtocolsPtr
std::string const * sourceCacheTempDir() const override
static std::string const input
std::string const & localConnectPrefix() const override
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > m_trivialDataCatalogs
std::string m_localConnectPrefix
std::string m_statisticsDestination
edm::propagate_const< struct addrinfo * > m_statisticsAddrInfo
bool const * m_enablePrefetchingPtr
std::string const rfioType(void) const override
unsigned int m_debugLevel
std::string const frontierConnect(std::string const &servlet) const
std::filesystem::path const storageDescriptionPath(edm::CatalogAttributes const &aDataCatalog) const override
std::string m_localConnectSuffix
std::set< std::string > m_statisticsInfo
bool useLocalConnectString() const override
std::vector< std::string > m_nativeProtocols
unsigned int const * sourceTTreeCacheSize() const override
std::string const & localConnectSuffix() const override
def split(sequence, size)
std::string const * m_cacheHintPtr
std::string const * m_readHintPtr
void computeStatisticsDestination()
unsigned int debugLevel() const override
unsigned int const * m_ttreeCacheSizePtr
SiteLocalConfigService(ParameterSet const &pset)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addContext(std::string const &context)
std::set< std::string > const * statisticsInfo() const override
static const char kEmptyString[1]
double const * sourceCacheMinFree() const override
std::vector< edm::CatalogAttributes > const & dataCatalogs() const override
bool m_useLocalConnectString
bool m_statisticsInfoAvail
std::string const * sourceCloneCacheHint() const override
std::string const lookupCalibConnect(std::string const &input) const override
bool enablePrefetching() const override
std::string const & siteName() const override