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") {
329 aCatalog.
site = site;
333 if (tmp_site.empty())
344 tinyxml2::XMLDocument
doc;
345 auto loadErr =
doc.LoadFile(
url.c_str());
346 if (loadErr != tinyxml2::XML_SUCCESS) {
380 auto rootElement =
doc.RootElement();
382 for (
auto site = rootElement->FirstChildElement(
"site"); site !=
nullptr;
383 site = site->NextSiblingElement(
"site")) {
384 auto subSite = site->FirstChildElement(
"subsite");
391 auto subSite_first_child = subSite->FirstChild();
392 if (subSite_first_child) {
394 ex <<
"Invalid site-local-config.xml. Subsite node has children!";
395 ex.
addContext(
"edm::SiteLocalConfigService::parse()");
402 auto eventData = site->FirstChildElement(
"event-data");
404 auto catalog = eventData->FirstChildElement(
"catalog");
413 auto rfiotype = eventData->FirstChildElement(
"rfiotype");
415 m_rfioType = safe(rfiotype->Attribute(
"value"));
428 auto dataAccess = site->FirstChildElement(
"data-access");
431 auto catalog = dataAccess->FirstChildElement(
"catalog");
447 auto calibData = site->FirstChildElement(
"calib-data");
450 auto frontierConnect = calibData->FirstChildElement(
"frontier-connect");
455 auto localConnect = calibData->FirstChildElement(
"local-connect");
459 <<
"It is illegal to include both frontier-connect and local-connect in the same XML file";
462 auto connectString = localConnect->FirstChildElement(
"connectString");
471 auto sourceConfig = site->FirstChildElement(
"source-config");
474 auto cacheTempDir = sourceConfig->FirstChildElement(
"cache-temp-dir");
481 auto cacheMinFree = sourceConfig->FirstChildElement(
"cache-min-free");
489 auto cacheHint = sourceConfig->FirstChildElement(
"cache-hint");
496 auto cloneCacheHint = sourceConfig->FirstChildElement(
"clone-cache-hint");
498 if (cloneCacheHint) {
503 auto readHint = sourceConfig->FirstChildElement(
"read-hint");
506 m_readHint = safe(readHint->Attribute(
"value"));
510 auto ttreeCacheSize = sourceConfig->FirstChildElement(
"ttree-cache-size");
512 if (ttreeCacheSize) {
517 auto timeout = sourceConfig->FirstChildElement(
"timeout-in-seconds");
524 auto statsDest = sourceConfig->FirstChildElement(
"statistics-destination");
531 std::string tmpStatisticsInfo = safe(statsDest->Attribute(
"info"));
536 auto prefetching = sourceConfig->FirstChildElement(
"prefetching");
543 auto nativeProtocol = sourceConfig->FirstChildElement(
"native-protocols");
545 if (nativeProtocol) {
546 for (
auto child = nativeProtocol->FirstChildElement();
child !=
nullptr;
558 std::vector<std::string> inputStrings;
562 struct addrinfo *
res;
563 struct addrinfo hints;
564 memset(&hints,
'\0',
sizeof(hints));
565 hints.ai_socktype = SOCK_DGRAM;
566 hints.ai_flags = AI_ADDRCONFIG;
567 hints.ai_family = AF_UNSPEC;
568 int e = getaddrinfo(
host.c_str(),
port.c_str(), &hints, &
res);
578 desc.setComment(
"Service to translate logical file names to physical file names.");
582 "Specify the file containing the site local config. Empty string will load from default directory.");
584 desc.addOptionalUntracked<
double>(
"overrideSourceCacheMinFree");
586 desc.addOptionalUntracked<
std::string>(
"overrideSourceCloneCacheHintDir")
587 ->setComment(
"Provide an alternate cache hint for fast cloning.");
589 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideSourceNativeProtocols");
590 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTTreeCacheSize");
591 desc.addOptionalUntracked<
unsigned int>(
"overrideSourceTimeout");
592 desc.addOptionalUntracked<
unsigned int>(
"debugLevel");
593 desc.addOptionalUntracked<
bool>(
"overridePrefetching")
594 ->setComment(
"Request ROOT to asynchronously prefetch I/O during computation.");
595 desc.addOptionalUntracked<
std::string>(
"overrideStatisticsDestination")
597 "Provide an alternate network destination for I/O statistics (must be in the form of host:port).");
598 desc.addOptionalUntracked<std::vector<std::string> >(
"overrideStatisticsInfo")
600 "Provide an alternate listing of statistics to send (comma separated list; current options are 'dn' or " 601 "'nodn'). If left blank, all information is snet (including DNs).");
602 desc.addOptionalUntracked<
bool>(
"overrideUseLocalConnectString");
605 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